diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
19 files changed, 2915 insertions, 1161 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs index 993d10f..3cbdde5 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs | |||
@@ -301,6 +301,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
301 | return null; | 301 | return null; |
302 | } | 302 | } |
303 | 303 | ||
304 | public static void StateChange(IScriptEngine engine, uint localID, UUID itemID) | ||
305 | { | ||
306 | // Remove a specific script | ||
307 | |||
308 | // Remove dataserver events | ||
309 | m_Dataserver[engine].RemoveEvents(localID, itemID); | ||
310 | |||
311 | IWorldComm comms = engine.World.RequestModuleInterface<IWorldComm>(); | ||
312 | if (comms != null) | ||
313 | comms.DeleteListener(itemID); | ||
314 | |||
315 | IXMLRPC xmlrpc = engine.World.RequestModuleInterface<IXMLRPC>(); | ||
316 | xmlrpc.DeleteChannels(itemID); | ||
317 | xmlrpc.CancelSRDRequests(itemID); | ||
318 | |||
319 | // Remove Sensors | ||
320 | m_SensorRepeat[engine].UnSetSenseRepeaterEvents(localID, itemID); | ||
321 | |||
322 | } | ||
323 | |||
304 | public static Object[] GetSerializationData(IScriptEngine engine, UUID itemID) | 324 | public static Object[] GetSerializationData(IScriptEngine engine, UUID itemID) |
305 | { | 325 | { |
306 | List<Object> data = new List<Object>(); | 326 | List<Object> data = new List<Object>(); |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs new file mode 100644 index 0000000..489c1c6 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs | |||
@@ -0,0 +1,118 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Reflection; | ||
30 | using System.Collections; | ||
31 | using System.Collections.Generic; | ||
32 | using System.Runtime.Remoting.Lifetime; | ||
33 | using OpenMetaverse; | ||
34 | using Nini.Config; | ||
35 | using OpenSim; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Region.CoreModules.World.LightShare; | ||
38 | using OpenSim.Region.Framework.Interfaces; | ||
39 | using OpenSim.Region.Framework.Scenes; | ||
40 | using OpenSim.Region.ScriptEngine.Shared; | ||
41 | using OpenSim.Region.ScriptEngine.Shared.Api.Plugins; | ||
42 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; | ||
43 | using OpenSim.Region.ScriptEngine.Interfaces; | ||
44 | using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces; | ||
45 | using OpenSim.Services.Interfaces; | ||
46 | |||
47 | using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat; | ||
48 | using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; | ||
49 | using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; | ||
50 | using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list; | ||
51 | using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion; | ||
52 | using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; | ||
53 | using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; | ||
54 | |||
55 | namespace OpenSim.Region.ScriptEngine.Shared.Api | ||
56 | { | ||
57 | [Serializable] | ||
58 | public class CM_Api : MarshalByRefObject, ICM_Api, IScriptApi | ||
59 | { | ||
60 | internal IScriptEngine m_ScriptEngine; | ||
61 | internal SceneObjectPart m_host; | ||
62 | internal uint m_localID; | ||
63 | internal UUID m_itemID; | ||
64 | internal bool m_CMFunctionsEnabled = false; | ||
65 | |||
66 | public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) | ||
67 | { | ||
68 | m_ScriptEngine = ScriptEngine; | ||
69 | m_host = host; | ||
70 | m_localID = localID; | ||
71 | m_itemID = itemID; | ||
72 | |||
73 | if (m_ScriptEngine.Config.GetBoolean("AllowCareminsterFunctions", false)) | ||
74 | m_CMFunctionsEnabled = true; | ||
75 | } | ||
76 | |||
77 | public override Object InitializeLifetimeService() | ||
78 | { | ||
79 | ILease lease = (ILease)base.InitializeLifetimeService(); | ||
80 | |||
81 | if (lease.CurrentState == LeaseState.Initial) | ||
82 | { | ||
83 | lease.InitialLeaseTime = TimeSpan.FromMinutes(0); | ||
84 | // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0); | ||
85 | // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0); | ||
86 | } | ||
87 | return lease; | ||
88 | } | ||
89 | |||
90 | public Scene World | ||
91 | { | ||
92 | get { return m_ScriptEngine.World; } | ||
93 | } | ||
94 | |||
95 | public string cmDetectedCountry(int number) | ||
96 | { | ||
97 | m_host.AddScriptLPS(1); | ||
98 | DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); | ||
99 | if (detectedParams == null) | ||
100 | return String.Empty; | ||
101 | return detectedParams.Country; | ||
102 | } | ||
103 | |||
104 | public string cmGetAgentCountry(LSL_Key key) | ||
105 | { | ||
106 | if (!World.Permissions.IsGod(m_host.OwnerID)) | ||
107 | return String.Empty; | ||
108 | |||
109 | UUID uuid; | ||
110 | |||
111 | if (!UUID.TryParse(key, out uuid)) | ||
112 | return String.Empty; | ||
113 | |||
114 | UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid); | ||
115 | return account.UserCountry; | ||
116 | } | ||
117 | } | ||
118 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index bb374ed..e2d17a7 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | |||
@@ -28,10 +28,12 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Diagnostics; //for [DebuggerNonUserCode] | ||
31 | using System.Runtime.Remoting.Lifetime; | 32 | using System.Runtime.Remoting.Lifetime; |
32 | using System.Text; | 33 | using System.Text; |
33 | using System.Threading; | 34 | using System.Threading; |
34 | using System.Text.RegularExpressions; | 35 | using System.Text.RegularExpressions; |
36 | using System.Timers; | ||
35 | using Nini.Config; | 37 | using Nini.Config; |
36 | using log4net; | 38 | using log4net; |
37 | using OpenMetaverse; | 39 | using OpenMetaverse; |
@@ -44,6 +46,7 @@ using OpenSim.Region.CoreModules.World.Land; | |||
44 | using OpenSim.Region.CoreModules.World.Terrain; | 46 | using OpenSim.Region.CoreModules.World.Terrain; |
45 | using OpenSim.Region.Framework.Interfaces; | 47 | using OpenSim.Region.Framework.Interfaces; |
46 | using OpenSim.Region.Framework.Scenes; | 48 | using OpenSim.Region.Framework.Scenes; |
49 | using OpenSim.Region.Framework.Scenes.Serialization; | ||
47 | using OpenSim.Region.Framework.Scenes.Animation; | 50 | using OpenSim.Region.Framework.Scenes.Animation; |
48 | using OpenSim.Region.Physics.Manager; | 51 | using OpenSim.Region.Physics.Manager; |
49 | using OpenSim.Region.ScriptEngine.Shared; | 52 | using OpenSim.Region.ScriptEngine.Shared; |
@@ -65,6 +68,7 @@ using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion; | |||
65 | using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; | 68 | using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; |
66 | using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; | 69 | using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; |
67 | using System.Reflection; | 70 | using System.Reflection; |
71 | using Timer = System.Timers.Timer; | ||
68 | 72 | ||
69 | namespace OpenSim.Region.ScriptEngine.Shared.Api | 73 | namespace OpenSim.Region.ScriptEngine.Shared.Api |
70 | { | 74 | { |
@@ -99,16 +103,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
99 | protected int m_notecardLineReadCharsMax = 255; | 103 | protected int m_notecardLineReadCharsMax = 255; |
100 | protected int m_scriptConsoleChannel = 0; | 104 | protected int m_scriptConsoleChannel = 0; |
101 | protected bool m_scriptConsoleChannelEnabled = false; | 105 | protected bool m_scriptConsoleChannelEnabled = false; |
106 | protected bool m_debuggerSafe = false; | ||
102 | protected IUrlModule m_UrlModule = null; | 107 | protected IUrlModule m_UrlModule = null; |
103 | protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache = | 108 | protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache = |
104 | new Dictionary<UUID, UserInfoCacheEntry>(); | 109 | new Dictionary<UUID, UserInfoCacheEntry>(); |
105 | 110 | ||
111 | protected Timer m_ShoutSayTimer; | ||
112 | protected int m_SayShoutCount = 0; | ||
113 | |||
106 | public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) | 114 | public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) |
107 | { | 115 | { |
116 | m_ShoutSayTimer = new Timer(1000); | ||
117 | m_ShoutSayTimer.Elapsed += SayShoutTimerElapsed; | ||
118 | m_ShoutSayTimer.AutoReset = true; | ||
119 | m_ShoutSayTimer.Start(); | ||
120 | |||
108 | m_ScriptEngine = ScriptEngine; | 121 | m_ScriptEngine = ScriptEngine; |
109 | m_host = host; | 122 | m_host = host; |
110 | m_localID = localID; | 123 | m_localID = localID; |
111 | m_itemID = itemID; | 124 | m_itemID = itemID; |
125 | m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false); | ||
112 | 126 | ||
113 | m_ScriptDelayFactor = | 127 | m_ScriptDelayFactor = |
114 | m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f); | 128 | m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f); |
@@ -156,6 +170,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
156 | get { return m_ScriptEngine.World; } | 170 | get { return m_ScriptEngine.World; } |
157 | } | 171 | } |
158 | 172 | ||
173 | [DebuggerNonUserCode] | ||
159 | public void state(string newState) | 174 | public void state(string newState) |
160 | { | 175 | { |
161 | m_ScriptEngine.SetState(m_itemID, newState); | 176 | m_ScriptEngine.SetState(m_itemID, newState); |
@@ -165,6 +180,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
165 | /// Reset the named script. The script must be present | 180 | /// Reset the named script. The script must be present |
166 | /// in the same prim. | 181 | /// in the same prim. |
167 | /// </summary> | 182 | /// </summary> |
183 | [DebuggerNonUserCode] | ||
168 | public void llResetScript() | 184 | public void llResetScript() |
169 | { | 185 | { |
170 | m_host.AddScriptLPS(1); | 186 | m_host.AddScriptLPS(1); |
@@ -221,9 +237,62 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
221 | } | 237 | } |
222 | } | 238 | } |
223 | 239 | ||
240 | public List<ScenePresence> GetLinkAvatars(int linkType) | ||
241 | { | ||
242 | List<ScenePresence> ret = new List<ScenePresence>(); | ||
243 | if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted) | ||
244 | return ret; | ||
245 | |||
246 | List<ScenePresence> avs = m_host.ParentGroup.GetLinkedAvatars(); | ||
247 | |||
248 | switch (linkType) | ||
249 | { | ||
250 | case ScriptBaseClass.LINK_SET: | ||
251 | return avs; | ||
252 | |||
253 | case ScriptBaseClass.LINK_ROOT: | ||
254 | return ret; | ||
255 | |||
256 | case ScriptBaseClass.LINK_ALL_OTHERS: | ||
257 | return avs; | ||
258 | |||
259 | case ScriptBaseClass.LINK_ALL_CHILDREN: | ||
260 | return avs; | ||
261 | |||
262 | case ScriptBaseClass.LINK_THIS: | ||
263 | return ret; | ||
264 | |||
265 | default: | ||
266 | if (linkType < 0) | ||
267 | return ret; | ||
268 | |||
269 | int partCount = m_host.ParentGroup.GetPartCount(); | ||
270 | |||
271 | if (linkType <= partCount) | ||
272 | { | ||
273 | return ret; | ||
274 | } | ||
275 | else | ||
276 | { | ||
277 | linkType = linkType - partCount; | ||
278 | if (linkType > avs.Count) | ||
279 | { | ||
280 | return ret; | ||
281 | } | ||
282 | else | ||
283 | { | ||
284 | ret.Add(avs[linkType-1]); | ||
285 | return ret; | ||
286 | } | ||
287 | } | ||
288 | } | ||
289 | } | ||
290 | |||
224 | public List<SceneObjectPart> GetLinkParts(int linkType) | 291 | public List<SceneObjectPart> GetLinkParts(int linkType) |
225 | { | 292 | { |
226 | List<SceneObjectPart> ret = new List<SceneObjectPart>(); | 293 | List<SceneObjectPart> ret = new List<SceneObjectPart>(); |
294 | if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted) | ||
295 | return ret; | ||
227 | ret.Add(m_host); | 296 | ret.Add(m_host); |
228 | 297 | ||
229 | switch (linkType) | 298 | switch (linkType) |
@@ -270,40 +339,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
270 | protected UUID InventorySelf() | 339 | protected UUID InventorySelf() |
271 | { | 340 | { |
272 | UUID invItemID = new UUID(); | 341 | UUID invItemID = new UUID(); |
273 | 342 | bool unlock = false; | |
274 | lock (m_host.TaskInventory) | 343 | if (!m_host.TaskInventory.IsReadLockedByMe()) |
275 | { | 344 | { |
276 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | 345 | m_host.TaskInventory.LockItemsForRead(true); |
346 | unlock = true; | ||
347 | } | ||
348 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | ||
349 | { | ||
350 | if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID) | ||
277 | { | 351 | { |
278 | if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID) | 352 | invItemID = inv.Key; |
279 | { | 353 | break; |
280 | invItemID = inv.Key; | ||
281 | break; | ||
282 | } | ||
283 | } | 354 | } |
284 | } | 355 | } |
285 | 356 | if (unlock) | |
357 | { | ||
358 | m_host.TaskInventory.LockItemsForRead(false); | ||
359 | } | ||
286 | return invItemID; | 360 | return invItemID; |
287 | } | 361 | } |
288 | 362 | ||
289 | protected UUID InventoryKey(string name, int type) | 363 | protected UUID InventoryKey(string name, int type) |
290 | { | 364 | { |
291 | m_host.AddScriptLPS(1); | 365 | m_host.AddScriptLPS(1); |
292 | 366 | m_host.TaskInventory.LockItemsForRead(true); | |
293 | lock (m_host.TaskInventory) | 367 | |
368 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | ||
294 | { | 369 | { |
295 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | 370 | if (inv.Value.Name == name) |
296 | { | 371 | { |
297 | if (inv.Value.Name == name) | 372 | m_host.TaskInventory.LockItemsForRead(false); |
373 | |||
374 | if (inv.Value.Type != type) | ||
298 | { | 375 | { |
299 | if (inv.Value.Type != type) | 376 | return UUID.Zero; |
300 | return UUID.Zero; | ||
301 | |||
302 | return inv.Value.AssetID; | ||
303 | } | 377 | } |
378 | |||
379 | return inv.Value.AssetID; | ||
304 | } | 380 | } |
305 | } | 381 | } |
306 | 382 | ||
383 | m_host.TaskInventory.LockItemsForRead(false); | ||
307 | return UUID.Zero; | 384 | return UUID.Zero; |
308 | } | 385 | } |
309 | 386 | ||
@@ -311,17 +388,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
311 | { | 388 | { |
312 | m_host.AddScriptLPS(1); | 389 | m_host.AddScriptLPS(1); |
313 | 390 | ||
314 | lock (m_host.TaskInventory) | 391 | |
392 | m_host.TaskInventory.LockItemsForRead(true); | ||
393 | |||
394 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | ||
315 | { | 395 | { |
316 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | 396 | if (inv.Value.Name == name) |
317 | { | 397 | { |
318 | if (inv.Value.Name == name) | 398 | m_host.TaskInventory.LockItemsForRead(false); |
319 | { | 399 | return inv.Value.AssetID; |
320 | return inv.Value.AssetID; | ||
321 | } | ||
322 | } | 400 | } |
323 | } | 401 | } |
324 | 402 | ||
403 | m_host.TaskInventory.LockItemsForRead(false); | ||
404 | |||
405 | |||
325 | return UUID.Zero; | 406 | return UUID.Zero; |
326 | } | 407 | } |
327 | 408 | ||
@@ -463,31 +544,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
463 | 544 | ||
464 | //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke | 545 | //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke |
465 | 546 | ||
466 | /// <summary> | 547 | // Utility function for llRot2Euler |
467 | /// Convert an LSL rotation to a Euler vector. | 548 | |
468 | /// </summary> | 549 | // normalize an angle between -PI and PI (-180 to +180 degrees) |
469 | /// <remarks> | 550 | protected double NormalizeAngle(double angle) |
470 | /// Using algorithm based off http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/quat_2_euler_paper_ver2-1.pdf | ||
471 | /// to avoid issues with singularity and rounding with Y rotation of +/- PI/2 | ||
472 | /// </remarks> | ||
473 | /// <param name="r"></param> | ||
474 | /// <returns></returns> | ||
475 | public LSL_Vector llRot2Euler(LSL_Rotation r) | ||
476 | { | 551 | { |
477 | m_host.AddScriptLPS(1); | 552 | if (angle > -Math.PI && angle < Math.PI) |
553 | return angle; | ||
478 | 554 | ||
479 | LSL_Vector v = new LSL_Vector(0.0, 0.0, 1.0) * r; // Z axis unit vector unaffected by Z rotation component of r. | 555 | int numPis = (int)(Math.PI / angle); |
480 | double m = LSL_Vector.Mag(v); // Just in case v isn't normalized, need magnitude for Asin() operation later. | 556 | double remainder = angle - Math.PI * numPis; |
481 | if (m == 0.0) return new LSL_Vector(); | 557 | if (numPis % 2 == 1) |
482 | double x = Math.Atan2(-v.y, v.z); | 558 | return Math.PI - angle; |
483 | double sin = v.x / m; | 559 | return remainder; |
484 | if (sin < -0.999999 || sin > 0.999999) x = 0.0; // Force X rotation to 0 at the singularities. | 560 | } |
485 | double y = Math.Asin(sin); | ||
486 | // Rotate X axis unit vector by r and unwind the X and Y rotations leaving only the Z rotation | ||
487 | v = new LSL_Vector(1.0, 0.0, 0.0) * ((r * new LSL_Rotation(Math.Sin(-x / 2.0), 0.0, 0.0, Math.Cos(-x / 2.0))) * new LSL_Rotation(0.0, Math.Sin(-y / 2.0), 0.0, Math.Cos(-y / 2.0))); | ||
488 | double z = Math.Atan2(v.y, v.x); | ||
489 | 561 | ||
490 | return new LSL_Vector(x, y, z); | 562 | public LSL_Vector llRot2Euler(LSL_Rotation q1) |
563 | { | ||
564 | m_host.AddScriptLPS(1); | ||
565 | LSL_Vector eul = new LSL_Vector(); | ||
566 | |||
567 | double sqw = q1.s*q1.s; | ||
568 | double sqx = q1.x*q1.x; | ||
569 | double sqy = q1.z*q1.z; | ||
570 | double sqz = q1.y*q1.y; | ||
571 | double unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor | ||
572 | double test = q1.x*q1.z + q1.y*q1.s; | ||
573 | if (test > 0.4999*unit) { // singularity at north pole | ||
574 | eul.z = 2 * Math.Atan2(q1.x,q1.s); | ||
575 | eul.y = Math.PI/2; | ||
576 | eul.x = 0; | ||
577 | return eul; | ||
578 | } | ||
579 | if (test < -0.4999*unit) { // singularity at south pole | ||
580 | eul.z = -2 * Math.Atan2(q1.x,q1.s); | ||
581 | eul.y = -Math.PI/2; | ||
582 | eul.x = 0; | ||
583 | return eul; | ||
584 | } | ||
585 | eul.z = Math.Atan2(2*q1.z*q1.s-2*q1.x*q1.y , sqx - sqy - sqz + sqw); | ||
586 | eul.y = Math.Asin(2*test/unit); | ||
587 | eul.x = Math.Atan2(2*q1.x*q1.s-2*q1.z*q1.y , -sqx + sqy - sqz + sqw); | ||
588 | return eul; | ||
491 | } | 589 | } |
492 | 590 | ||
493 | /* From wiki: | 591 | /* From wiki: |
@@ -689,77 +787,76 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
689 | { | 787 | { |
690 | //A and B should both be normalized | 788 | //A and B should both be normalized |
691 | m_host.AddScriptLPS(1); | 789 | m_host.AddScriptLPS(1); |
692 | LSL_Rotation rotBetween; | 790 | /* This method is more accurate than the SL one, and thus causes problems |
693 | // Check for zero vectors. If either is zero, return zero rotation. Otherwise, | 791 | for scripts that deal with the SL inaccuracy around 180-degrees -.- .._. |
694 | // continue calculation. | 792 | |
695 | if (a == new LSL_Vector(0.0f, 0.0f, 0.0f) || b == new LSL_Vector(0.0f, 0.0f, 0.0f)) | 793 | double dotProduct = LSL_Vector.Dot(a, b); |
794 | LSL_Vector crossProduct = LSL_Vector.Cross(a, b); | ||
795 | double magProduct = LSL_Vector.Mag(a) * LSL_Vector.Mag(b); | ||
796 | double angle = Math.Acos(dotProduct / magProduct); | ||
797 | LSL_Vector axis = LSL_Vector.Norm(crossProduct); | ||
798 | double s = Math.Sin(angle / 2); | ||
799 | |||
800 | double x = axis.x * s; | ||
801 | double y = axis.y * s; | ||
802 | double z = axis.z * s; | ||
803 | double w = Math.Cos(angle / 2); | ||
804 | |||
805 | if (Double.IsNaN(x) || Double.IsNaN(y) || Double.IsNaN(z) || Double.IsNaN(w)) | ||
806 | return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f); | ||
807 | |||
808 | return new LSL_Rotation((float)x, (float)y, (float)z, (float)w); | ||
809 | */ | ||
810 | |||
811 | // This method mimics the 180 errors found in SL | ||
812 | // See www.euclideanspace.com... angleBetween | ||
813 | LSL_Vector vec_a = a; | ||
814 | LSL_Vector vec_b = b; | ||
815 | |||
816 | // Eliminate zero length | ||
817 | LSL_Float vec_a_mag = LSL_Vector.Mag(vec_a); | ||
818 | LSL_Float vec_b_mag = LSL_Vector.Mag(vec_b); | ||
819 | if (vec_a_mag < 0.00001 || | ||
820 | vec_b_mag < 0.00001) | ||
696 | { | 821 | { |
697 | rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f); | 822 | return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f); |
698 | } | 823 | } |
699 | else | 824 | |
825 | // Normalize | ||
826 | vec_a = llVecNorm(vec_a); | ||
827 | vec_b = llVecNorm(vec_b); | ||
828 | |||
829 | // Calculate axis and rotation angle | ||
830 | LSL_Vector axis = vec_a % vec_b; | ||
831 | LSL_Float cos_theta = vec_a * vec_b; | ||
832 | |||
833 | // Check if parallel | ||
834 | if (cos_theta > 0.99999) | ||
700 | { | 835 | { |
701 | a = LSL_Vector.Norm(a); | 836 | return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f); |
702 | b = LSL_Vector.Norm(b); | 837 | } |
703 | double dotProduct = LSL_Vector.Dot(a, b); | 838 | |
704 | // There are two degenerate cases possible. These are for vectors 180 or | 839 | // Check if anti-parallel |
705 | // 0 degrees apart. These have to be detected and handled individually. | 840 | else if (cos_theta < -0.99999) |
706 | // | 841 | { |
707 | // Check for vectors 180 degrees apart. | 842 | LSL_Vector orthog_axis = new LSL_Vector(1.0, 0.0, 0.0) - (vec_a.x / (vec_a * vec_a) * vec_a); |
708 | // A dot product of -1 would mean the angle between vectors is 180 degrees. | 843 | if (LSL_Vector.Mag(orthog_axis) < 0.000001) orthog_axis = new LSL_Vector(0.0, 0.0, 1.0); |
709 | if (dotProduct < -0.9999999f) | 844 | return new LSL_Rotation((float)orthog_axis.x, (float)orthog_axis.y, (float)orthog_axis.z, 0.0); |
710 | { | 845 | } |
711 | // First assume X axis is orthogonal to the vectors. | 846 | else // other rotation |
712 | LSL_Vector orthoVector = new LSL_Vector(1.0f, 0.0f, 0.0f); | 847 | { |
713 | orthoVector = orthoVector - a * (a.x / LSL_Vector.Dot(a, a)); | 848 | LSL_Float theta = (LSL_Float)Math.Acos(cos_theta) * 0.5f; |
714 | // Check for near zero vector. A very small non-zero number here will create | 849 | axis = llVecNorm(axis); |
715 | // a rotation in an undesired direction. | 850 | double x, y, z, s, t; |
716 | if (LSL_Vector.Mag(orthoVector) > 0.0001) | 851 | s = Math.Cos(theta); |
717 | { | 852 | t = Math.Sin(theta); |
718 | rotBetween = new LSL_Rotation(orthoVector.x, orthoVector.y, orthoVector.z, 0.0f); | 853 | x = axis.x * t; |
719 | } | 854 | y = axis.y * t; |
720 | // If the magnitude of the vector was near zero, then assume the X axis is not | 855 | z = axis.z * t; |
721 | // orthogonal and use the Z axis instead. | 856 | return new LSL_Rotation(x,y,z,s); |
722 | else | ||
723 | { | ||
724 | // Set 180 z rotation. | ||
725 | rotBetween = new LSL_Rotation(0.0f, 0.0f, 1.0f, 0.0f); | ||
726 | } | ||
727 | } | ||
728 | // Check for parallel vectors. | ||
729 | // A dot product of 1 would mean the angle between vectors is 0 degrees. | ||
730 | else if (dotProduct > 0.9999999f) | ||
731 | { | ||
732 | // Set zero rotation. | ||
733 | rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f); | ||
734 | } | ||
735 | else | ||
736 | { | ||
737 | // All special checks have been performed so get the axis of rotation. | ||
738 | LSL_Vector crossProduct = LSL_Vector.Cross(a, b); | ||
739 | // Quarternion s value is the length of the unit vector + dot product. | ||
740 | double qs = 1.0 + dotProduct; | ||
741 | rotBetween = new LSL_Rotation(crossProduct.x, crossProduct.y, crossProduct.z, qs); | ||
742 | // Normalize the rotation. | ||
743 | double mag = LSL_Rotation.Mag(rotBetween); | ||
744 | // We shouldn't have to worry about a divide by zero here. The qs value will be | ||
745 | // non-zero because we already know if we're here, then the dotProduct is not -1 so | ||
746 | // qs will not be zero. Also, we've already handled the input vectors being zero so the | ||
747 | // crossProduct vector should also not be zero. | ||
748 | rotBetween.x = rotBetween.x / mag; | ||
749 | rotBetween.y = rotBetween.y / mag; | ||
750 | rotBetween.z = rotBetween.z / mag; | ||
751 | rotBetween.s = rotBetween.s / mag; | ||
752 | // Check for undefined values and set zero rotation if any found. This code might not actually be required | ||
753 | // any longer since zero vectors are checked for at the top. | ||
754 | if (Double.IsNaN(rotBetween.x) || Double.IsNaN(rotBetween.y) || Double.IsNaN(rotBetween.z) || Double.IsNaN(rotBetween.s)) | ||
755 | { | ||
756 | rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f); | ||
757 | } | ||
758 | } | ||
759 | } | 857 | } |
760 | return rotBetween; | ||
761 | } | 858 | } |
762 | 859 | ||
763 | public void llWhisper(int channelID, string text) | 860 | public void llWhisper(int channelID, string text) |
764 | { | 861 | { |
765 | m_host.AddScriptLPS(1); | 862 | m_host.AddScriptLPS(1); |
@@ -779,6 +876,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
779 | { | 876 | { |
780 | m_host.AddScriptLPS(1); | 877 | m_host.AddScriptLPS(1); |
781 | 878 | ||
879 | if (channelID == 0) | ||
880 | m_SayShoutCount++; | ||
881 | |||
882 | if (m_SayShoutCount >= 11) | ||
883 | ScriptSleep(2000); | ||
884 | |||
782 | if (m_scriptConsoleChannelEnabled && (channelID == m_scriptConsoleChannel)) | 885 | if (m_scriptConsoleChannelEnabled && (channelID == m_scriptConsoleChannel)) |
783 | { | 886 | { |
784 | Console.WriteLine(text); | 887 | Console.WriteLine(text); |
@@ -801,6 +904,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
801 | { | 904 | { |
802 | m_host.AddScriptLPS(1); | 905 | m_host.AddScriptLPS(1); |
803 | 906 | ||
907 | if (channelID == 0) | ||
908 | m_SayShoutCount++; | ||
909 | |||
910 | if (m_SayShoutCount >= 11) | ||
911 | ScriptSleep(2000); | ||
912 | |||
804 | if (text.Length > 1023) | 913 | if (text.Length > 1023) |
805 | text = text.Substring(0, 1023); | 914 | text = text.Substring(0, 1023); |
806 | 915 | ||
@@ -1101,10 +1210,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1101 | return detectedParams.TouchUV; | 1210 | return detectedParams.TouchUV; |
1102 | } | 1211 | } |
1103 | 1212 | ||
1213 | [DebuggerNonUserCode] | ||
1104 | public virtual void llDie() | 1214 | public virtual void llDie() |
1105 | { | 1215 | { |
1106 | m_host.AddScriptLPS(1); | 1216 | m_host.AddScriptLPS(1); |
1107 | throw new SelfDeleteException(); | 1217 | if (!m_host.ParentGroup.IsAttachment) throw new SelfDeleteException(); |
1108 | } | 1218 | } |
1109 | 1219 | ||
1110 | public LSL_Float llGround(LSL_Vector offset) | 1220 | public LSL_Float llGround(LSL_Vector offset) |
@@ -1177,6 +1287,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1177 | 1287 | ||
1178 | public void llSetStatus(int status, int value) | 1288 | public void llSetStatus(int status, int value) |
1179 | { | 1289 | { |
1290 | if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted) | ||
1291 | return; | ||
1180 | m_host.AddScriptLPS(1); | 1292 | m_host.AddScriptLPS(1); |
1181 | 1293 | ||
1182 | int statusrotationaxis = 0; | 1294 | int statusrotationaxis = 0; |
@@ -1406,6 +1518,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1406 | { | 1518 | { |
1407 | m_host.AddScriptLPS(1); | 1519 | m_host.AddScriptLPS(1); |
1408 | 1520 | ||
1521 | SetColor(m_host, color, face); | ||
1522 | } | ||
1523 | |||
1524 | protected void SetColor(SceneObjectPart part, LSL_Vector color, int face) | ||
1525 | { | ||
1526 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) | ||
1527 | return; | ||
1528 | |||
1529 | Primitive.TextureEntry tex = part.Shape.Textures; | ||
1530 | Color4 texcolor; | ||
1531 | if (face >= 0 && face < GetNumberOfSides(part)) | ||
1532 | { | ||
1533 | texcolor = tex.CreateFace((uint)face).RGBA; | ||
1534 | texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f); | ||
1535 | texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f); | ||
1536 | texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f); | ||
1537 | tex.FaceTextures[face].RGBA = texcolor; | ||
1538 | part.UpdateTextureEntry(tex.GetBytes()); | ||
1539 | return; | ||
1540 | } | ||
1541 | else if (face == ScriptBaseClass.ALL_SIDES) | ||
1542 | { | ||
1543 | for (uint i = 0; i < GetNumberOfSides(part); i++) | ||
1544 | { | ||
1545 | if (tex.FaceTextures[i] != null) | ||
1546 | { | ||
1547 | texcolor = tex.FaceTextures[i].RGBA; | ||
1548 | texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f); | ||
1549 | texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f); | ||
1550 | texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f); | ||
1551 | tex.FaceTextures[i].RGBA = texcolor; | ||
1552 | } | ||
1553 | texcolor = tex.DefaultTexture.RGBA; | ||
1554 | texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f); | ||
1555 | texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f); | ||
1556 | texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f); | ||
1557 | tex.DefaultTexture.RGBA = texcolor; | ||
1558 | } | ||
1559 | part.UpdateTextureEntry(tex.GetBytes()); | ||
1560 | return; | ||
1561 | } | ||
1562 | |||
1409 | if (face == ScriptBaseClass.ALL_SIDES) | 1563 | if (face == ScriptBaseClass.ALL_SIDES) |
1410 | face = SceneObjectPart.ALL_SIDES; | 1564 | face = SceneObjectPart.ALL_SIDES; |
1411 | 1565 | ||
@@ -1414,6 +1568,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1414 | 1568 | ||
1415 | public void SetTexGen(SceneObjectPart part, int face,int style) | 1569 | public void SetTexGen(SceneObjectPart part, int face,int style) |
1416 | { | 1570 | { |
1571 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) | ||
1572 | return; | ||
1573 | |||
1417 | Primitive.TextureEntry tex = part.Shape.Textures; | 1574 | Primitive.TextureEntry tex = part.Shape.Textures; |
1418 | MappingType textype; | 1575 | MappingType textype; |
1419 | textype = MappingType.Default; | 1576 | textype = MappingType.Default; |
@@ -1444,6 +1601,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1444 | 1601 | ||
1445 | public void SetGlow(SceneObjectPart part, int face, float glow) | 1602 | public void SetGlow(SceneObjectPart part, int face, float glow) |
1446 | { | 1603 | { |
1604 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) | ||
1605 | return; | ||
1606 | |||
1447 | Primitive.TextureEntry tex = part.Shape.Textures; | 1607 | Primitive.TextureEntry tex = part.Shape.Textures; |
1448 | if (face >= 0 && face < GetNumberOfSides(part)) | 1608 | if (face >= 0 && face < GetNumberOfSides(part)) |
1449 | { | 1609 | { |
@@ -1469,6 +1629,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1469 | 1629 | ||
1470 | public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump) | 1630 | public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump) |
1471 | { | 1631 | { |
1632 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) | ||
1633 | return; | ||
1472 | 1634 | ||
1473 | Shininess sval = new Shininess(); | 1635 | Shininess sval = new Shininess(); |
1474 | 1636 | ||
@@ -1519,6 +1681,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1519 | 1681 | ||
1520 | public void SetFullBright(SceneObjectPart part, int face, bool bright) | 1682 | public void SetFullBright(SceneObjectPart part, int face, bool bright) |
1521 | { | 1683 | { |
1684 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) | ||
1685 | return; | ||
1686 | |||
1522 | Primitive.TextureEntry tex = part.Shape.Textures; | 1687 | Primitive.TextureEntry tex = part.Shape.Textures; |
1523 | if (face >= 0 && face < GetNumberOfSides(part)) | 1688 | if (face >= 0 && face < GetNumberOfSides(part)) |
1524 | { | 1689 | { |
@@ -1579,13 +1744,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1579 | m_host.AddScriptLPS(1); | 1744 | m_host.AddScriptLPS(1); |
1580 | 1745 | ||
1581 | List<SceneObjectPart> parts = GetLinkParts(linknumber); | 1746 | List<SceneObjectPart> parts = GetLinkParts(linknumber); |
1582 | 1747 | if (parts.Count > 0) | |
1583 | foreach (SceneObjectPart part in parts) | 1748 | { |
1584 | SetAlpha(part, alpha, face); | 1749 | try |
1750 | { | ||
1751 | parts[0].ParentGroup.areUpdatesSuspended = true; | ||
1752 | foreach (SceneObjectPart part in parts) | ||
1753 | SetAlpha(part, alpha, face); | ||
1754 | } | ||
1755 | finally | ||
1756 | { | ||
1757 | parts[0].ParentGroup.areUpdatesSuspended = false; | ||
1758 | } | ||
1759 | } | ||
1585 | } | 1760 | } |
1586 | 1761 | ||
1587 | protected void SetAlpha(SceneObjectPart part, double alpha, int face) | 1762 | protected void SetAlpha(SceneObjectPart part, double alpha, int face) |
1588 | { | 1763 | { |
1764 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) | ||
1765 | return; | ||
1766 | |||
1589 | Primitive.TextureEntry tex = part.Shape.Textures; | 1767 | Primitive.TextureEntry tex = part.Shape.Textures; |
1590 | Color4 texcolor; | 1768 | Color4 texcolor; |
1591 | if (face >= 0 && face < GetNumberOfSides(part)) | 1769 | if (face >= 0 && face < GetNumberOfSides(part)) |
@@ -1638,7 +1816,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1638 | protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction, | 1816 | protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction, |
1639 | float wind, float tension, LSL_Vector Force) | 1817 | float wind, float tension, LSL_Vector Force) |
1640 | { | 1818 | { |
1641 | if (part == null) | 1819 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) |
1642 | return; | 1820 | return; |
1643 | 1821 | ||
1644 | if (flexi) | 1822 | if (flexi) |
@@ -1672,7 +1850,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1672 | /// <param name="falloff"></param> | 1850 | /// <param name="falloff"></param> |
1673 | protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff) | 1851 | protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff) |
1674 | { | 1852 | { |
1675 | if (part == null) | 1853 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) |
1676 | return; | 1854 | return; |
1677 | 1855 | ||
1678 | if (light) | 1856 | if (light) |
@@ -1749,15 +1927,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1749 | m_host.AddScriptLPS(1); | 1927 | m_host.AddScriptLPS(1); |
1750 | 1928 | ||
1751 | List<SceneObjectPart> parts = GetLinkParts(linknumber); | 1929 | List<SceneObjectPart> parts = GetLinkParts(linknumber); |
1752 | 1930 | if (parts.Count > 0) | |
1753 | foreach (SceneObjectPart part in parts) | 1931 | { |
1754 | SetTexture(part, texture, face); | 1932 | try |
1755 | 1933 | { | |
1934 | parts[0].ParentGroup.areUpdatesSuspended = true; | ||
1935 | foreach (SceneObjectPart part in parts) | ||
1936 | SetTexture(part, texture, face); | ||
1937 | } | ||
1938 | finally | ||
1939 | { | ||
1940 | parts[0].ParentGroup.areUpdatesSuspended = false; | ||
1941 | } | ||
1942 | } | ||
1756 | ScriptSleep(200); | 1943 | ScriptSleep(200); |
1757 | } | 1944 | } |
1758 | 1945 | ||
1759 | protected void SetTexture(SceneObjectPart part, string texture, int face) | 1946 | protected void SetTexture(SceneObjectPart part, string texture, int face) |
1760 | { | 1947 | { |
1948 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) | ||
1949 | return; | ||
1950 | |||
1761 | UUID textureID = new UUID(); | 1951 | UUID textureID = new UUID(); |
1762 | 1952 | ||
1763 | textureID = InventoryKey(texture, (int)AssetType.Texture); | 1953 | textureID = InventoryKey(texture, (int)AssetType.Texture); |
@@ -1802,6 +1992,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1802 | 1992 | ||
1803 | protected void ScaleTexture(SceneObjectPart part, double u, double v, int face) | 1993 | protected void ScaleTexture(SceneObjectPart part, double u, double v, int face) |
1804 | { | 1994 | { |
1995 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) | ||
1996 | return; | ||
1997 | |||
1805 | Primitive.TextureEntry tex = part.Shape.Textures; | 1998 | Primitive.TextureEntry tex = part.Shape.Textures; |
1806 | if (face >= 0 && face < GetNumberOfSides(part)) | 1999 | if (face >= 0 && face < GetNumberOfSides(part)) |
1807 | { | 2000 | { |
@@ -1838,6 +2031,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1838 | 2031 | ||
1839 | protected void OffsetTexture(SceneObjectPart part, double u, double v, int face) | 2032 | protected void OffsetTexture(SceneObjectPart part, double u, double v, int face) |
1840 | { | 2033 | { |
2034 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) | ||
2035 | return; | ||
2036 | |||
1841 | Primitive.TextureEntry tex = part.Shape.Textures; | 2037 | Primitive.TextureEntry tex = part.Shape.Textures; |
1842 | if (face >= 0 && face < GetNumberOfSides(part)) | 2038 | if (face >= 0 && face < GetNumberOfSides(part)) |
1843 | { | 2039 | { |
@@ -1874,6 +2070,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1874 | 2070 | ||
1875 | protected void RotateTexture(SceneObjectPart part, double rotation, int face) | 2071 | protected void RotateTexture(SceneObjectPart part, double rotation, int face) |
1876 | { | 2072 | { |
2073 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) | ||
2074 | return; | ||
2075 | |||
1877 | Primitive.TextureEntry tex = part.Shape.Textures; | 2076 | Primitive.TextureEntry tex = part.Shape.Textures; |
1878 | if (face >= 0 && face < GetNumberOfSides(part)) | 2077 | if (face >= 0 && face < GetNumberOfSides(part)) |
1879 | { | 2078 | { |
@@ -1978,26 +2177,76 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1978 | return real_vec; | 2177 | return real_vec; |
1979 | } | 2178 | } |
1980 | 2179 | ||
2180 | public LSL_Integer llSetRegionPos(LSL_Vector pos) | ||
2181 | { | ||
2182 | return new LSL_Integer(SetRegionPos(m_host, pos)); | ||
2183 | } | ||
2184 | |||
2185 | protected int SetRegionPos(SceneObjectPart part, LSL_Vector targetPos) | ||
2186 | { | ||
2187 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) | ||
2188 | return 0; | ||
2189 | |||
2190 | SceneObjectGroup grp = part.ParentGroup; | ||
2191 | |||
2192 | if (grp.IsAttachment) | ||
2193 | return 0; | ||
2194 | |||
2195 | if (grp.RootPart.PhysActor != null && grp.RootPart.PhysActor.IsPhysical) | ||
2196 | return 0; | ||
2197 | |||
2198 | if (targetPos.x < -10.0f || targetPos.x >= (float)Constants.RegionSize || targetPos.y < -10.0f || targetPos.y >= (float)Constants.RegionSize || targetPos.z < 0 || targetPos.z >= 4096.0f) | ||
2199 | return 0; | ||
2200 | |||
2201 | float constrainedX = (float)targetPos.x; | ||
2202 | float constrainedY = (float)targetPos.y; | ||
2203 | |||
2204 | if (constrainedX < 0.0f) | ||
2205 | constrainedX = 0.0f; | ||
2206 | if (constrainedY < 0.0f) | ||
2207 | constrainedY = 0.0f; | ||
2208 | if (constrainedX >= (float)Constants.RegionSize) | ||
2209 | constrainedX = (float)Constants.RegionSize - 0.1f; | ||
2210 | if (constrainedY >= (float)Constants.RegionSize) | ||
2211 | constrainedY = (float)Constants.RegionSize -0.1f; | ||
2212 | |||
2213 | float ground = World.GetGroundHeight(constrainedX, constrainedY); | ||
2214 | |||
2215 | if (targetPos.z < ground) | ||
2216 | targetPos.z = ground; | ||
2217 | |||
2218 | Vector3 dest = new Vector3((float)targetPos.x, (float)targetPos.y, (float)targetPos.z); | ||
2219 | |||
2220 | if (!World.Permissions.CanObjectEntry(grp.UUID, false, dest)) | ||
2221 | return 0; | ||
2222 | |||
2223 | grp.UpdateGroupPosition(dest); | ||
2224 | |||
2225 | return 1; | ||
2226 | } | ||
2227 | |||
1981 | protected void SetPos(SceneObjectPart part, LSL_Vector targetPos) | 2228 | protected void SetPos(SceneObjectPart part, LSL_Vector targetPos) |
1982 | { | 2229 | { |
1983 | // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos) | 2230 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) |
2231 | return; | ||
2232 | |||
1984 | LSL_Vector currentPos = GetPartLocalPos(part); | 2233 | LSL_Vector currentPos = GetPartLocalPos(part); |
2234 | LSL_Vector toPos = GetSetPosTarget(part, targetPos, currentPos); | ||
1985 | 2235 | ||
1986 | float ground = World.GetGroundHeight((float)targetPos.x, (float)targetPos.y); | ||
1987 | bool disable_underground_movement = m_ScriptEngine.Config.GetBoolean("DisableUndergroundMovement", true); | ||
1988 | 2236 | ||
1989 | if (part.ParentGroup.RootPart == part) | 2237 | if (part.ParentGroup.RootPart == part) |
1990 | { | 2238 | { |
1991 | if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0) | ||
1992 | targetPos.z = ground; | ||
1993 | SceneObjectGroup parent = part.ParentGroup; | 2239 | SceneObjectGroup parent = part.ParentGroup; |
1994 | LSL_Vector real_vec = SetPosAdjust(currentPos, targetPos); | 2240 | Vector3 dest = new Vector3((float)toPos.x, (float)toPos.y, (float)toPos.z); |
1995 | parent.UpdateGroupPosition(new Vector3((float)real_vec.x, (float)real_vec.y, (float)real_vec.z)); | 2241 | if (!World.Permissions.CanObjectEntry(parent.UUID, false, dest)) |
2242 | return; | ||
2243 | Util.FireAndForget(delegate(object x) { | ||
2244 | parent.UpdateGroupPosition(dest); | ||
2245 | }); | ||
1996 | } | 2246 | } |
1997 | else | 2247 | else |
1998 | { | 2248 | { |
1999 | LSL_Vector rel_vec = SetPosAdjust(currentPos, targetPos); | 2249 | part.OffsetPosition = new Vector3((float)toPos.x, (float)toPos.y, (float)toPos.z); |
2000 | part.OffsetPosition = new Vector3((float)rel_vec.x, (float)rel_vec.y, (float)rel_vec.z); | ||
2001 | SceneObjectGroup parent = part.ParentGroup; | 2250 | SceneObjectGroup parent = part.ParentGroup; |
2002 | parent.HasGroupChanged = true; | 2251 | parent.HasGroupChanged = true; |
2003 | parent.ScheduleGroupForTerseUpdate(); | 2252 | parent.ScheduleGroupForTerseUpdate(); |
@@ -2028,11 +2277,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2028 | } | 2277 | } |
2029 | else | 2278 | else |
2030 | { | 2279 | { |
2031 | if (m_host.IsRoot) | 2280 | if (part.IsRoot) |
2032 | { | 2281 | { |
2033 | return new LSL_Vector(m_host.AttachedPos.X, | 2282 | return new LSL_Vector(part.AttachedPos.X, |
2034 | m_host.AttachedPos.Y, | 2283 | part.AttachedPos.Y, |
2035 | m_host.AttachedPos.Z); | 2284 | part.AttachedPos.Z); |
2036 | } | 2285 | } |
2037 | else | 2286 | else |
2038 | { | 2287 | { |
@@ -2048,9 +2297,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2048 | m_host.AddScriptLPS(1); | 2297 | m_host.AddScriptLPS(1); |
2049 | 2298 | ||
2050 | // try to let this work as in SL... | 2299 | // try to let this work as in SL... |
2051 | if (m_host.ParentID == 0) | 2300 | if (m_host.LinkNum < 2) |
2052 | { | 2301 | { |
2053 | // special case: If we are root, rotate complete SOG to new rotation | 2302 | // Special case: If we are root, rotate complete SOG to new |
2303 | // rotation. | ||
2304 | // We are root if the link number is 0 (single prim) or 1 | ||
2305 | // (root prim). ParentID may be nonzero in attachments and | ||
2306 | // using it would cause attachments and HUDs to rotate | ||
2307 | // to the wrong positions. | ||
2054 | SetRot(m_host, Rot2Quaternion(rot)); | 2308 | SetRot(m_host, Rot2Quaternion(rot)); |
2055 | } | 2309 | } |
2056 | else | 2310 | else |
@@ -2075,6 +2329,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2075 | 2329 | ||
2076 | protected void SetRot(SceneObjectPart part, Quaternion rot) | 2330 | protected void SetRot(SceneObjectPart part, Quaternion rot) |
2077 | { | 2331 | { |
2332 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) | ||
2333 | return; | ||
2334 | |||
2078 | part.UpdateRotation(rot); | 2335 | part.UpdateRotation(rot); |
2079 | // Update rotation does not move the object in the physics scene if it's a linkset. | 2336 | // Update rotation does not move the object in the physics scene if it's a linkset. |
2080 | 2337 | ||
@@ -2227,13 +2484,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2227 | public void llApplyRotationalImpulse(LSL_Vector force, int local) | 2484 | public void llApplyRotationalImpulse(LSL_Vector force, int local) |
2228 | { | 2485 | { |
2229 | m_host.AddScriptLPS(1); | 2486 | m_host.AddScriptLPS(1); |
2230 | m_host.ApplyAngularImpulse(new Vector3((float)force.x, (float)force.y, (float)force.z), local != 0); | 2487 | m_host.ParentGroup.RootPart.ApplyAngularImpulse(new Vector3((float)force.x, (float)force.y, (float)force.z), local != 0); |
2231 | } | 2488 | } |
2232 | 2489 | ||
2233 | public void llSetTorque(LSL_Vector torque, int local) | 2490 | public void llSetTorque(LSL_Vector torque, int local) |
2234 | { | 2491 | { |
2235 | m_host.AddScriptLPS(1); | 2492 | m_host.AddScriptLPS(1); |
2236 | m_host.SetAngularImpulse(new Vector3((float)torque.x, (float)torque.y, (float)torque.z), local != 0); | 2493 | m_host.ParentGroup.RootPart.SetAngularImpulse(new Vector3((float)torque.x, (float)torque.y, (float)torque.z), local != 0); |
2237 | } | 2494 | } |
2238 | 2495 | ||
2239 | public LSL_Vector llGetTorque() | 2496 | public LSL_Vector llGetTorque() |
@@ -2698,12 +2955,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2698 | 2955 | ||
2699 | m_host.AddScriptLPS(1); | 2956 | m_host.AddScriptLPS(1); |
2700 | 2957 | ||
2958 | m_host.TaskInventory.LockItemsForRead(true); | ||
2701 | TaskInventoryItem item = m_host.TaskInventory[invItemID]; | 2959 | TaskInventoryItem item = m_host.TaskInventory[invItemID]; |
2702 | 2960 | m_host.TaskInventory.LockItemsForRead(false); | |
2703 | lock (m_host.TaskInventory) | ||
2704 | { | ||
2705 | item = m_host.TaskInventory[invItemID]; | ||
2706 | } | ||
2707 | 2961 | ||
2708 | if (item.PermsGranter == UUID.Zero) | 2962 | if (item.PermsGranter == UUID.Zero) |
2709 | return 0; | 2963 | return 0; |
@@ -2844,34 +3098,39 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2844 | public void llLookAt(LSL_Vector target, double strength, double damping) | 3098 | public void llLookAt(LSL_Vector target, double strength, double damping) |
2845 | { | 3099 | { |
2846 | m_host.AddScriptLPS(1); | 3100 | m_host.AddScriptLPS(1); |
2847 | // Determine where we are looking from | ||
2848 | LSL_Vector from = llGetPos(); | ||
2849 | 3101 | ||
2850 | // Work out the normalised vector from the source to the target | 3102 | // Get the normalized vector to the target |
2851 | LSL_Vector delta = llVecNorm(target - from); | 3103 | LSL_Vector d1 = llVecNorm(target - llGetPos()); |
2852 | LSL_Vector angle = new LSL_Vector(0,0,0); | ||
2853 | 3104 | ||
2854 | // Calculate the yaw | 3105 | // Get the bearing (yaw) |
2855 | // subtracting PI_BY_TWO is required to compensate for the odd SL co-ordinate system | 3106 | LSL_Vector a1 = new LSL_Vector(0,0,0); |
2856 | angle.x = llAtan2(delta.z, delta.y) - ScriptBaseClass.PI_BY_TWO; | 3107 | a1.z = llAtan2(d1.y, d1.x); |
2857 | 3108 | ||
2858 | // Calculate pitch | 3109 | // Get the elevation (pitch) |
2859 | angle.y = llAtan2(delta.x, llSqrt((delta.y * delta.y) + (delta.z * delta.z))); | 3110 | LSL_Vector a2 = new LSL_Vector(0,0,0); |
3111 | a2.y= -llAtan2(d1.z, llSqrt((d1.x * d1.x) + (d1.y * d1.y))); | ||
2860 | 3112 | ||
2861 | // we need to convert from a vector describing | 3113 | LSL_Rotation r1 = llEuler2Rot(a1); |
2862 | // the angles of rotation in radians into rotation value | 3114 | LSL_Rotation r2 = llEuler2Rot(a2); |
3115 | LSL_Rotation r3 = new LSL_Rotation(0.000000, 0.707107, 0.000000, 0.707107); | ||
2863 | 3116 | ||
2864 | LSL_Rotation rot = llEuler2Rot(angle); | 3117 | if (m_host.PhysActor == null || !m_host.PhysActor.IsPhysical) |
2865 | |||
2866 | // Per discussion with Melanie, for non-physical objects llLookAt appears to simply | ||
2867 | // set the rotation of the object, copy that behavior | ||
2868 | if (strength == 0 || m_host.PhysActor == null || !m_host.PhysActor.IsPhysical) | ||
2869 | { | 3118 | { |
2870 | llSetRot(rot); | 3119 | // Do nothing if either value is 0 (this has been checked in SL) |
3120 | if (strength <= 0.0 || damping <= 0.0) | ||
3121 | return; | ||
3122 | |||
3123 | llSetRot(r3 * r2 * r1); | ||
2871 | } | 3124 | } |
2872 | else | 3125 | else |
2873 | { | 3126 | { |
2874 | m_host.StartLookAt(Rot2Quaternion(rot), (float)strength, (float)damping); | 3127 | if (strength == 0) |
3128 | { | ||
3129 | llSetRot(r3 * r2 * r1); | ||
3130 | return; | ||
3131 | } | ||
3132 | |||
3133 | m_host.StartLookAt(Rot2Quaternion(r3 * r2 * r1), (float)strength, (float)damping); | ||
2875 | } | 3134 | } |
2876 | } | 3135 | } |
2877 | 3136 | ||
@@ -2921,13 +3180,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2921 | { | 3180 | { |
2922 | TaskInventoryItem item; | 3181 | TaskInventoryItem item; |
2923 | 3182 | ||
2924 | lock (m_host.TaskInventory) | 3183 | m_host.TaskInventory.LockItemsForRead(true); |
3184 | if (!m_host.TaskInventory.ContainsKey(InventorySelf())) | ||
2925 | { | 3185 | { |
2926 | if (!m_host.TaskInventory.ContainsKey(InventorySelf())) | 3186 | m_host.TaskInventory.LockItemsForRead(false); |
2927 | return; | 3187 | return; |
2928 | else | ||
2929 | item = m_host.TaskInventory[InventorySelf()]; | ||
2930 | } | 3188 | } |
3189 | else | ||
3190 | { | ||
3191 | item = m_host.TaskInventory[InventorySelf()]; | ||
3192 | } | ||
3193 | m_host.TaskInventory.LockItemsForRead(false); | ||
2931 | 3194 | ||
2932 | if (item.PermsGranter != UUID.Zero) | 3195 | if (item.PermsGranter != UUID.Zero) |
2933 | { | 3196 | { |
@@ -2949,13 +3212,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2949 | { | 3212 | { |
2950 | TaskInventoryItem item; | 3213 | TaskInventoryItem item; |
2951 | 3214 | ||
3215 | m_host.TaskInventory.LockItemsForRead(true); | ||
2952 | lock (m_host.TaskInventory) | 3216 | lock (m_host.TaskInventory) |
2953 | { | 3217 | { |
3218 | |||
2954 | if (!m_host.TaskInventory.ContainsKey(InventorySelf())) | 3219 | if (!m_host.TaskInventory.ContainsKey(InventorySelf())) |
3220 | { | ||
3221 | m_host.TaskInventory.LockItemsForRead(false); | ||
2955 | return; | 3222 | return; |
3223 | } | ||
2956 | else | 3224 | else |
3225 | { | ||
2957 | item = m_host.TaskInventory[InventorySelf()]; | 3226 | item = m_host.TaskInventory[InventorySelf()]; |
3227 | } | ||
2958 | } | 3228 | } |
3229 | m_host.TaskInventory.LockItemsForRead(false); | ||
2959 | 3230 | ||
2960 | m_host.AddScriptLPS(1); | 3231 | m_host.AddScriptLPS(1); |
2961 | 3232 | ||
@@ -2987,18 +3258,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2987 | { | 3258 | { |
2988 | m_host.AddScriptLPS(1); | 3259 | m_host.AddScriptLPS(1); |
2989 | 3260 | ||
2990 | // if (m_host.ParentGroup.RootPart.AttachmentPoint == 0) | ||
2991 | // return; | ||
2992 | |||
2993 | TaskInventoryItem item; | 3261 | TaskInventoryItem item; |
2994 | 3262 | ||
2995 | lock (m_host.TaskInventory) | 3263 | m_host.TaskInventory.LockItemsForRead(true); |
3264 | |||
3265 | if (!m_host.TaskInventory.ContainsKey(InventorySelf())) | ||
2996 | { | 3266 | { |
2997 | if (!m_host.TaskInventory.ContainsKey(InventorySelf())) | 3267 | m_host.TaskInventory.LockItemsForRead(false); |
2998 | return; | 3268 | return; |
2999 | else | ||
3000 | item = m_host.TaskInventory[InventorySelf()]; | ||
3001 | } | 3269 | } |
3270 | else | ||
3271 | { | ||
3272 | item = m_host.TaskInventory[InventorySelf()]; | ||
3273 | } | ||
3274 | |||
3275 | m_host.TaskInventory.LockItemsForRead(false); | ||
3002 | 3276 | ||
3003 | if (item.PermsGranter != m_host.OwnerID) | 3277 | if (item.PermsGranter != m_host.OwnerID) |
3004 | return; | 3278 | return; |
@@ -3024,13 +3298,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3024 | 3298 | ||
3025 | TaskInventoryItem item; | 3299 | TaskInventoryItem item; |
3026 | 3300 | ||
3027 | lock (m_host.TaskInventory) | 3301 | m_host.TaskInventory.LockItemsForRead(true); |
3302 | |||
3303 | if (!m_host.TaskInventory.ContainsKey(InventorySelf())) | ||
3028 | { | 3304 | { |
3029 | if (!m_host.TaskInventory.ContainsKey(InventorySelf())) | 3305 | m_host.TaskInventory.LockItemsForRead(false); |
3030 | return; | 3306 | return; |
3031 | else | 3307 | } |
3032 | item = m_host.TaskInventory[InventorySelf()]; | 3308 | else |
3309 | { | ||
3310 | item = m_host.TaskInventory[InventorySelf()]; | ||
3033 | } | 3311 | } |
3312 | m_host.TaskInventory.LockItemsForRead(false); | ||
3313 | |||
3034 | 3314 | ||
3035 | if (item.PermsGranter != m_host.OwnerID) | 3315 | if (item.PermsGranter != m_host.OwnerID) |
3036 | return; | 3316 | return; |
@@ -3077,6 +3357,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3077 | 3357 | ||
3078 | public void llInstantMessage(string user, string message) | 3358 | public void llInstantMessage(string user, string message) |
3079 | { | 3359 | { |
3360 | UUID result; | ||
3361 | if (!UUID.TryParse(user, out result)) | ||
3362 | { | ||
3363 | ShoutError("An invalid key was passed to llInstantMessage"); | ||
3364 | ScriptSleep(2000); | ||
3365 | return; | ||
3366 | } | ||
3367 | |||
3368 | |||
3080 | m_host.AddScriptLPS(1); | 3369 | m_host.AddScriptLPS(1); |
3081 | 3370 | ||
3082 | // We may be able to use ClientView.SendInstantMessage here, but we need a client instance. | 3371 | // We may be able to use ClientView.SendInstantMessage here, but we need a client instance. |
@@ -3091,14 +3380,34 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3091 | UUID friendTransactionID = UUID.Random(); | 3380 | UUID friendTransactionID = UUID.Random(); |
3092 | 3381 | ||
3093 | //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID); | 3382 | //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID); |
3094 | 3383 | ||
3095 | GridInstantMessage msg = new GridInstantMessage(); | 3384 | GridInstantMessage msg = new GridInstantMessage(); |
3096 | msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid; | 3385 | msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid; |
3097 | msg.toAgentID = new Guid(user); // toAgentID.Guid; | 3386 | msg.toAgentID = new Guid(user); // toAgentID.Guid; |
3098 | msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here | 3387 | msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here |
3099 | // m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message); | 3388 | // m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message); |
3100 | // m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString()); | 3389 | // m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString()); |
3101 | msg.timestamp = (uint)Util.UnixTimeSinceEpoch();// timestamp; | 3390 | // DateTime dt = DateTime.UtcNow; |
3391 | // | ||
3392 | // // Ticks from UtcNow, but make it look like local. Evil, huh? | ||
3393 | // dt = DateTime.SpecifyKind(dt, DateTimeKind.Local); | ||
3394 | // | ||
3395 | // try | ||
3396 | // { | ||
3397 | // // Convert that to the PST timezone | ||
3398 | // TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("America/Los_Angeles"); | ||
3399 | // dt = TimeZoneInfo.ConvertTime(dt, timeZoneInfo); | ||
3400 | // } | ||
3401 | // catch | ||
3402 | // { | ||
3403 | // // No logging here, as it could be VERY spammy | ||
3404 | // } | ||
3405 | // | ||
3406 | // // And make it look local again to fool the unix time util | ||
3407 | // dt = DateTime.SpecifyKind(dt, DateTimeKind.Utc); | ||
3408 | |||
3409 | msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); | ||
3410 | |||
3102 | //if (client != null) | 3411 | //if (client != null) |
3103 | //{ | 3412 | //{ |
3104 | msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName; | 3413 | msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName; |
@@ -3112,12 +3421,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3112 | msg.message = message.Substring(0, 1024); | 3421 | msg.message = message.Substring(0, 1024); |
3113 | else | 3422 | else |
3114 | msg.message = message; | 3423 | msg.message = message; |
3115 | msg.dialog = (byte)19; // messgage from script ??? // dialog; | 3424 | msg.dialog = (byte)19; // MessageFromObject |
3116 | msg.fromGroup = false;// fromGroup; | 3425 | msg.fromGroup = false;// fromGroup; |
3117 | msg.offline = (byte)0; //offline; | 3426 | msg.offline = (byte)0; //offline; |
3118 | msg.ParentEstateID = 0; //ParentEstateID; | 3427 | msg.ParentEstateID = World.RegionInfo.EstateSettings.EstateID; |
3119 | msg.Position = new Vector3(m_host.AbsolutePosition); | 3428 | msg.Position = new Vector3(m_host.AbsolutePosition); |
3120 | msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid; | 3429 | msg.RegionID = World.RegionInfo.RegionID.Guid; |
3121 | msg.binaryBucket | 3430 | msg.binaryBucket |
3122 | = Util.StringToBytes256( | 3431 | = Util.StringToBytes256( |
3123 | "{0}/{1}/{2}/{3}", | 3432 | "{0}/{1}/{2}/{3}", |
@@ -3145,7 +3454,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3145 | } | 3454 | } |
3146 | 3455 | ||
3147 | emailModule.SendEmail(m_host.UUID, address, subject, message); | 3456 | emailModule.SendEmail(m_host.UUID, address, subject, message); |
3148 | ScriptSleep(20000); | 3457 | ScriptSleep(15000); |
3149 | } | 3458 | } |
3150 | 3459 | ||
3151 | public void llGetNextEmail(string address, string subject) | 3460 | public void llGetNextEmail(string address, string subject) |
@@ -3284,14 +3593,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3284 | 3593 | ||
3285 | TaskInventoryItem item; | 3594 | TaskInventoryItem item; |
3286 | 3595 | ||
3287 | lock (m_host.TaskInventory) | 3596 | m_host.TaskInventory.LockItemsForRead(true); |
3597 | if (!m_host.TaskInventory.ContainsKey(InventorySelf())) | ||
3288 | { | 3598 | { |
3289 | if (!m_host.TaskInventory.ContainsKey(InventorySelf())) | 3599 | m_host.TaskInventory.LockItemsForRead(false); |
3290 | return; | 3600 | return; |
3291 | else | ||
3292 | item = m_host.TaskInventory[InventorySelf()]; | ||
3293 | } | 3601 | } |
3294 | 3602 | else | |
3603 | { | ||
3604 | item = m_host.TaskInventory[InventorySelf()]; | ||
3605 | } | ||
3606 | m_host.TaskInventory.LockItemsForRead(false); | ||
3295 | if (item.PermsGranter == UUID.Zero) | 3607 | if (item.PermsGranter == UUID.Zero) |
3296 | return; | 3608 | return; |
3297 | 3609 | ||
@@ -3321,13 +3633,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3321 | 3633 | ||
3322 | TaskInventoryItem item; | 3634 | TaskInventoryItem item; |
3323 | 3635 | ||
3324 | lock (m_host.TaskInventory) | 3636 | m_host.TaskInventory.LockItemsForRead(true); |
3637 | if (!m_host.TaskInventory.ContainsKey(InventorySelf())) | ||
3325 | { | 3638 | { |
3326 | if (!m_host.TaskInventory.ContainsKey(InventorySelf())) | 3639 | m_host.TaskInventory.LockItemsForRead(false); |
3327 | return; | 3640 | return; |
3328 | else | ||
3329 | item = m_host.TaskInventory[InventorySelf()]; | ||
3330 | } | 3641 | } |
3642 | else | ||
3643 | { | ||
3644 | item = m_host.TaskInventory[InventorySelf()]; | ||
3645 | } | ||
3646 | m_host.TaskInventory.LockItemsForRead(false); | ||
3647 | |||
3331 | 3648 | ||
3332 | if (item.PermsGranter == UUID.Zero) | 3649 | if (item.PermsGranter == UUID.Zero) |
3333 | return; | 3650 | return; |
@@ -3394,10 +3711,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3394 | 3711 | ||
3395 | TaskInventoryItem item; | 3712 | TaskInventoryItem item; |
3396 | 3713 | ||
3397 | lock (m_host.TaskInventory) | 3714 | |
3715 | m_host.TaskInventory.LockItemsForRead(true); | ||
3716 | if (!m_host.TaskInventory.ContainsKey(invItemID)) | ||
3717 | { | ||
3718 | m_host.TaskInventory.LockItemsForRead(false); | ||
3719 | return; | ||
3720 | } | ||
3721 | else | ||
3398 | { | 3722 | { |
3399 | item = m_host.TaskInventory[invItemID]; | 3723 | item = m_host.TaskInventory[invItemID]; |
3400 | } | 3724 | } |
3725 | m_host.TaskInventory.LockItemsForRead(false); | ||
3401 | 3726 | ||
3402 | if (agentID == UUID.Zero || perm == 0) // Releasing permissions | 3727 | if (agentID == UUID.Zero || perm == 0) // Releasing permissions |
3403 | { | 3728 | { |
@@ -3425,15 +3750,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3425 | int implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS | | 3750 | int implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS | |
3426 | ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION | | 3751 | ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION | |
3427 | ScriptBaseClass.PERMISSION_CONTROL_CAMERA | | 3752 | ScriptBaseClass.PERMISSION_CONTROL_CAMERA | |
3753 | ScriptBaseClass.PERMISSION_TRACK_CAMERA | | ||
3428 | ScriptBaseClass.PERMISSION_ATTACH; | 3754 | ScriptBaseClass.PERMISSION_ATTACH; |
3429 | 3755 | ||
3430 | if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms | 3756 | if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms |
3431 | { | 3757 | { |
3432 | lock (m_host.TaskInventory) | 3758 | m_host.TaskInventory.LockItemsForWrite(true); |
3433 | { | 3759 | m_host.TaskInventory[invItemID].PermsGranter = agentID; |
3434 | m_host.TaskInventory[invItemID].PermsGranter = agentID; | 3760 | m_host.TaskInventory[invItemID].PermsMask = perm; |
3435 | m_host.TaskInventory[invItemID].PermsMask = perm; | 3761 | m_host.TaskInventory.LockItemsForWrite(false); |
3436 | } | ||
3437 | 3762 | ||
3438 | m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( | 3763 | m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( |
3439 | "run_time_permissions", new Object[] { | 3764 | "run_time_permissions", new Object[] { |
@@ -3443,28 +3768,44 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3443 | return; | 3768 | return; |
3444 | } | 3769 | } |
3445 | } | 3770 | } |
3446 | else if (m_host.SitTargetAvatar == agentID) // Sitting avatar | 3771 | else |
3447 | { | 3772 | { |
3448 | // When agent is sitting, certain permissions are implicit if requested from sitting agent | 3773 | bool sitting = false; |
3449 | int implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION | | 3774 | if (m_host.SitTargetAvatar == agentID) |
3450 | ScriptBaseClass.PERMISSION_CONTROL_CAMERA | | 3775 | { |
3451 | ScriptBaseClass.PERMISSION_TRACK_CAMERA | | 3776 | sitting = true; |
3452 | ScriptBaseClass.PERMISSION_TAKE_CONTROLS; | 3777 | } |
3778 | else | ||
3779 | { | ||
3780 | foreach (SceneObjectPart p in m_host.ParentGroup.Parts) | ||
3781 | { | ||
3782 | if (p.SitTargetAvatar == agentID) | ||
3783 | sitting = true; | ||
3784 | } | ||
3785 | } | ||
3453 | 3786 | ||
3454 | if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms | 3787 | if (sitting) |
3455 | { | 3788 | { |
3456 | lock (m_host.TaskInventory) | 3789 | // When agent is sitting, certain permissions are implicit if requested from sitting agent |
3790 | int implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION | | ||
3791 | ScriptBaseClass.PERMISSION_CONTROL_CAMERA | | ||
3792 | ScriptBaseClass.PERMISSION_TRACK_CAMERA | | ||
3793 | ScriptBaseClass.PERMISSION_TAKE_CONTROLS; | ||
3794 | |||
3795 | if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms | ||
3457 | { | 3796 | { |
3797 | m_host.TaskInventory.LockItemsForWrite(true); | ||
3458 | m_host.TaskInventory[invItemID].PermsGranter = agentID; | 3798 | m_host.TaskInventory[invItemID].PermsGranter = agentID; |
3459 | m_host.TaskInventory[invItemID].PermsMask = perm; | 3799 | m_host.TaskInventory[invItemID].PermsMask = perm; |
3460 | } | 3800 | m_host.TaskInventory.LockItemsForWrite(false); |
3461 | 3801 | ||
3462 | m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( | 3802 | m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( |
3463 | "run_time_permissions", new Object[] { | 3803 | "run_time_permissions", new Object[] { |
3464 | new LSL_Integer(perm) }, | 3804 | new LSL_Integer(perm) }, |
3465 | new DetectParams[0])); | 3805 | new DetectParams[0])); |
3466 | 3806 | ||
3467 | return; | 3807 | return; |
3808 | } | ||
3468 | } | 3809 | } |
3469 | } | 3810 | } |
3470 | 3811 | ||
@@ -3478,11 +3819,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3478 | 3819 | ||
3479 | if (!m_waitingForScriptAnswer) | 3820 | if (!m_waitingForScriptAnswer) |
3480 | { | 3821 | { |
3481 | lock (m_host.TaskInventory) | 3822 | m_host.TaskInventory.LockItemsForWrite(true); |
3482 | { | 3823 | m_host.TaskInventory[invItemID].PermsGranter = agentID; |
3483 | m_host.TaskInventory[invItemID].PermsGranter = agentID; | 3824 | m_host.TaskInventory[invItemID].PermsMask = 0; |
3484 | m_host.TaskInventory[invItemID].PermsMask = 0; | 3825 | m_host.TaskInventory.LockItemsForWrite(false); |
3485 | } | ||
3486 | 3826 | ||
3487 | presence.ControllingClient.OnScriptAnswer += handleScriptAnswer; | 3827 | presence.ControllingClient.OnScriptAnswer += handleScriptAnswer; |
3488 | m_waitingForScriptAnswer=true; | 3828 | m_waitingForScriptAnswer=true; |
@@ -3517,10 +3857,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3517 | if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) | 3857 | if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) |
3518 | llReleaseControls(); | 3858 | llReleaseControls(); |
3519 | 3859 | ||
3520 | lock (m_host.TaskInventory) | 3860 | |
3521 | { | 3861 | m_host.TaskInventory.LockItemsForWrite(true); |
3522 | m_host.TaskInventory[invItemID].PermsMask = answer; | 3862 | m_host.TaskInventory[invItemID].PermsMask = answer; |
3523 | } | 3863 | m_host.TaskInventory.LockItemsForWrite(false); |
3864 | |||
3524 | 3865 | ||
3525 | m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( | 3866 | m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( |
3526 | "run_time_permissions", new Object[] { | 3867 | "run_time_permissions", new Object[] { |
@@ -3532,16 +3873,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3532 | { | 3873 | { |
3533 | m_host.AddScriptLPS(1); | 3874 | m_host.AddScriptLPS(1); |
3534 | 3875 | ||
3535 | lock (m_host.TaskInventory) | 3876 | m_host.TaskInventory.LockItemsForRead(true); |
3877 | |||
3878 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | ||
3536 | { | 3879 | { |
3537 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | 3880 | if (item.Type == 10 && item.ItemID == m_itemID) |
3538 | { | 3881 | { |
3539 | if (item.Type == 10 && item.ItemID == m_itemID) | 3882 | m_host.TaskInventory.LockItemsForRead(false); |
3540 | { | 3883 | return item.PermsGranter.ToString(); |
3541 | return item.PermsGranter.ToString(); | ||
3542 | } | ||
3543 | } | 3884 | } |
3544 | } | 3885 | } |
3886 | m_host.TaskInventory.LockItemsForRead(false); | ||
3545 | 3887 | ||
3546 | return UUID.Zero.ToString(); | 3888 | return UUID.Zero.ToString(); |
3547 | } | 3889 | } |
@@ -3550,19 +3892,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3550 | { | 3892 | { |
3551 | m_host.AddScriptLPS(1); | 3893 | m_host.AddScriptLPS(1); |
3552 | 3894 | ||
3553 | lock (m_host.TaskInventory) | 3895 | m_host.TaskInventory.LockItemsForRead(true); |
3896 | |||
3897 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | ||
3554 | { | 3898 | { |
3555 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | 3899 | if (item.Type == 10 && item.ItemID == m_itemID) |
3556 | { | 3900 | { |
3557 | if (item.Type == 10 && item.ItemID == m_itemID) | 3901 | int perms = item.PermsMask; |
3558 | { | 3902 | if (m_automaticLinkPermission) |
3559 | int perms = item.PermsMask; | 3903 | perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS; |
3560 | if (m_automaticLinkPermission) | 3904 | m_host.TaskInventory.LockItemsForRead(false); |
3561 | perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS; | 3905 | return perms; |
3562 | return perms; | ||
3563 | } | ||
3564 | } | 3906 | } |
3565 | } | 3907 | } |
3908 | m_host.TaskInventory.LockItemsForRead(false); | ||
3566 | 3909 | ||
3567 | return 0; | 3910 | return 0; |
3568 | } | 3911 | } |
@@ -3584,9 +3927,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3584 | public void llSetLinkColor(int linknumber, LSL_Vector color, int face) | 3927 | public void llSetLinkColor(int linknumber, LSL_Vector color, int face) |
3585 | { | 3928 | { |
3586 | List<SceneObjectPart> parts = GetLinkParts(linknumber); | 3929 | List<SceneObjectPart> parts = GetLinkParts(linknumber); |
3587 | 3930 | if (parts.Count > 0) | |
3588 | foreach (SceneObjectPart part in parts) | 3931 | { |
3589 | part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face); | 3932 | try |
3933 | { | ||
3934 | parts[0].ParentGroup.areUpdatesSuspended = true; | ||
3935 | foreach (SceneObjectPart part in parts) | ||
3936 | part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face); | ||
3937 | } | ||
3938 | finally | ||
3939 | { | ||
3940 | parts[0].ParentGroup.areUpdatesSuspended = false; | ||
3941 | } | ||
3942 | } | ||
3590 | } | 3943 | } |
3591 | 3944 | ||
3592 | public void llCreateLink(string target, int parent) | 3945 | public void llCreateLink(string target, int parent) |
@@ -3599,11 +3952,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3599 | return; | 3952 | return; |
3600 | 3953 | ||
3601 | TaskInventoryItem item; | 3954 | TaskInventoryItem item; |
3602 | lock (m_host.TaskInventory) | 3955 | m_host.TaskInventory.LockItemsForRead(true); |
3603 | { | 3956 | item = m_host.TaskInventory[invItemID]; |
3604 | item = m_host.TaskInventory[invItemID]; | 3957 | m_host.TaskInventory.LockItemsForRead(false); |
3605 | } | 3958 | |
3606 | |||
3607 | if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 | 3959 | if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 |
3608 | && !m_automaticLinkPermission) | 3960 | && !m_automaticLinkPermission) |
3609 | { | 3961 | { |
@@ -3620,11 +3972,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3620 | 3972 | ||
3621 | if (targetPart.ParentGroup.AttachmentPoint != 0) | 3973 | if (targetPart.ParentGroup.AttachmentPoint != 0) |
3622 | return; // Fail silently if attached | 3974 | return; // Fail silently if attached |
3975 | |||
3976 | if (targetPart.ParentGroup.RootPart.OwnerID != m_host.ParentGroup.RootPart.OwnerID) | ||
3977 | return; | ||
3978 | |||
3623 | SceneObjectGroup parentPrim = null, childPrim = null; | 3979 | SceneObjectGroup parentPrim = null, childPrim = null; |
3624 | 3980 | ||
3625 | if (targetPart != null) | 3981 | if (targetPart != null) |
3626 | { | 3982 | { |
3627 | if (parent != 0) { | 3983 | if (parent != 0) |
3984 | { | ||
3628 | parentPrim = m_host.ParentGroup; | 3985 | parentPrim = m_host.ParentGroup; |
3629 | childPrim = targetPart.ParentGroup; | 3986 | childPrim = targetPart.ParentGroup; |
3630 | } | 3987 | } |
@@ -3636,7 +3993,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3636 | 3993 | ||
3637 | // Required for linking | 3994 | // Required for linking |
3638 | childPrim.RootPart.ClearUpdateSchedule(); | 3995 | childPrim.RootPart.ClearUpdateSchedule(); |
3639 | parentPrim.LinkToGroup(childPrim); | 3996 | parentPrim.LinkToGroup(childPrim, true); |
3640 | } | 3997 | } |
3641 | 3998 | ||
3642 | parentPrim.TriggerScriptChangedEvent(Changed.LINK); | 3999 | parentPrim.TriggerScriptChangedEvent(Changed.LINK); |
@@ -3655,16 +4012,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3655 | m_host.AddScriptLPS(1); | 4012 | m_host.AddScriptLPS(1); |
3656 | UUID invItemID = InventorySelf(); | 4013 | UUID invItemID = InventorySelf(); |
3657 | 4014 | ||
3658 | lock (m_host.TaskInventory) | 4015 | m_host.TaskInventory.LockItemsForRead(true); |
3659 | { | ||
3660 | if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 | 4016 | if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 |
3661 | && !m_automaticLinkPermission) | 4017 | && !m_automaticLinkPermission) |
3662 | { | 4018 | { |
3663 | ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); | 4019 | ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); |
4020 | m_host.TaskInventory.LockItemsForRead(false); | ||
3664 | return; | 4021 | return; |
3665 | } | 4022 | } |
3666 | } | 4023 | m_host.TaskInventory.LockItemsForRead(false); |
3667 | 4024 | ||
3668 | if (linknum < ScriptBaseClass.LINK_THIS) | 4025 | if (linknum < ScriptBaseClass.LINK_THIS) |
3669 | return; | 4026 | return; |
3670 | 4027 | ||
@@ -3703,10 +4060,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3703 | // Restructuring Multiple Prims. | 4060 | // Restructuring Multiple Prims. |
3704 | List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts); | 4061 | List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts); |
3705 | parts.Remove(parentPrim.RootPart); | 4062 | parts.Remove(parentPrim.RootPart); |
3706 | foreach (SceneObjectPart part in parts) | 4063 | if (parts.Count > 0) |
3707 | { | 4064 | { |
3708 | parentPrim.DelinkFromGroup(part.LocalId, true); | 4065 | try |
4066 | { | ||
4067 | parts[0].ParentGroup.areUpdatesSuspended = true; | ||
4068 | foreach (SceneObjectPart part in parts) | ||
4069 | { | ||
4070 | parentPrim.DelinkFromGroup(part.LocalId, true); | ||
4071 | } | ||
4072 | } | ||
4073 | finally | ||
4074 | { | ||
4075 | parts[0].ParentGroup.areUpdatesSuspended = false; | ||
4076 | } | ||
3709 | } | 4077 | } |
4078 | |||
3710 | parentPrim.HasGroupChanged = true; | 4079 | parentPrim.HasGroupChanged = true; |
3711 | parentPrim.ScheduleGroupForFullUpdate(); | 4080 | parentPrim.ScheduleGroupForFullUpdate(); |
3712 | parentPrim.TriggerScriptChangedEvent(Changed.LINK); | 4081 | parentPrim.TriggerScriptChangedEvent(Changed.LINK); |
@@ -3715,12 +4084,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3715 | { | 4084 | { |
3716 | SceneObjectPart newRoot = parts[0]; | 4085 | SceneObjectPart newRoot = parts[0]; |
3717 | parts.Remove(newRoot); | 4086 | parts.Remove(newRoot); |
3718 | foreach (SceneObjectPart part in parts) | 4087 | |
4088 | try | ||
3719 | { | 4089 | { |
3720 | // Required for linking | 4090 | parts[0].ParentGroup.areUpdatesSuspended = true; |
3721 | part.ClearUpdateSchedule(); | 4091 | foreach (SceneObjectPart part in parts) |
3722 | newRoot.ParentGroup.LinkToGroup(part.ParentGroup); | 4092 | { |
4093 | part.ClearUpdateSchedule(); | ||
4094 | newRoot.ParentGroup.LinkToGroup(part.ParentGroup); | ||
4095 | } | ||
3723 | } | 4096 | } |
4097 | finally | ||
4098 | { | ||
4099 | parts[0].ParentGroup.areUpdatesSuspended = false; | ||
4100 | } | ||
4101 | |||
4102 | |||
3724 | newRoot.ParentGroup.HasGroupChanged = true; | 4103 | newRoot.ParentGroup.HasGroupChanged = true; |
3725 | newRoot.ParentGroup.ScheduleGroupForFullUpdate(); | 4104 | newRoot.ParentGroup.ScheduleGroupForFullUpdate(); |
3726 | } | 4105 | } |
@@ -3740,6 +4119,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3740 | public void llBreakAllLinks() | 4119 | public void llBreakAllLinks() |
3741 | { | 4120 | { |
3742 | m_host.AddScriptLPS(1); | 4121 | m_host.AddScriptLPS(1); |
4122 | |||
4123 | UUID invItemID = InventorySelf(); | ||
4124 | |||
4125 | TaskInventoryItem item; | ||
4126 | m_host.TaskInventory.LockItemsForRead(true); | ||
4127 | item = m_host.TaskInventory[invItemID]; | ||
4128 | m_host.TaskInventory.LockItemsForRead(false); | ||
4129 | |||
4130 | if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 | ||
4131 | && !m_automaticLinkPermission) | ||
4132 | { | ||
4133 | ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); | ||
4134 | return; | ||
4135 | } | ||
4136 | |||
3743 | SceneObjectGroup parentPrim = m_host.ParentGroup; | 4137 | SceneObjectGroup parentPrim = m_host.ParentGroup; |
3744 | if (parentPrim.AttachmentPoint != 0) | 4138 | if (parentPrim.AttachmentPoint != 0) |
3745 | return; // Fail silently if attached | 4139 | return; // Fail silently if attached |
@@ -3759,25 +4153,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3759 | public LSL_String llGetLinkKey(int linknum) | 4153 | public LSL_String llGetLinkKey(int linknum) |
3760 | { | 4154 | { |
3761 | m_host.AddScriptLPS(1); | 4155 | m_host.AddScriptLPS(1); |
3762 | List<UUID> keytable = new List<UUID>(); | ||
3763 | // parse for sitting avatare-uuids | ||
3764 | World.ForEachRootScenePresence(delegate(ScenePresence presence) | ||
3765 | { | ||
3766 | if (presence.ParentID != 0 && m_host.ParentGroup.HasChildPrim(presence.ParentID)) | ||
3767 | keytable.Add(presence.UUID); | ||
3768 | }); | ||
3769 | |||
3770 | int totalprims = m_host.ParentGroup.PrimCount + keytable.Count; | ||
3771 | if (linknum > m_host.ParentGroup.PrimCount && linknum <= totalprims) | ||
3772 | { | ||
3773 | return keytable[totalprims - linknum].ToString(); | ||
3774 | } | ||
3775 | |||
3776 | if (linknum == 1 && m_host.ParentGroup.PrimCount == 1 && keytable.Count == 1) | ||
3777 | { | ||
3778 | return m_host.UUID.ToString(); | ||
3779 | } | ||
3780 | |||
3781 | SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknum); | 4156 | SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknum); |
3782 | if (part != null) | 4157 | if (part != null) |
3783 | { | 4158 | { |
@@ -3785,6 +4160,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3785 | } | 4160 | } |
3786 | else | 4161 | else |
3787 | { | 4162 | { |
4163 | if (linknum > m_host.ParentGroup.PrimCount || (linknum == 1 && m_host.ParentGroup.PrimCount == 1)) | ||
4164 | { | ||
4165 | linknum -= (m_host.ParentGroup.PrimCount) + 1; | ||
4166 | |||
4167 | if (linknum < 0) | ||
4168 | return UUID.Zero.ToString(); | ||
4169 | |||
4170 | List<ScenePresence> avatars = GetLinkAvatars(ScriptBaseClass.LINK_SET); | ||
4171 | if (avatars.Count > linknum) | ||
4172 | { | ||
4173 | return avatars[linknum].UUID.ToString(); | ||
4174 | } | ||
4175 | } | ||
3788 | return UUID.Zero.ToString(); | 4176 | return UUID.Zero.ToString(); |
3789 | } | 4177 | } |
3790 | } | 4178 | } |
@@ -3884,17 +4272,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3884 | m_host.AddScriptLPS(1); | 4272 | m_host.AddScriptLPS(1); |
3885 | int count = 0; | 4273 | int count = 0; |
3886 | 4274 | ||
3887 | lock (m_host.TaskInventory) | 4275 | m_host.TaskInventory.LockItemsForRead(true); |
4276 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | ||
3888 | { | 4277 | { |
3889 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | 4278 | if (inv.Value.Type == type || type == -1) |
3890 | { | 4279 | { |
3891 | if (inv.Value.Type == type || type == -1) | 4280 | count = count + 1; |
3892 | { | ||
3893 | count = count + 1; | ||
3894 | } | ||
3895 | } | 4281 | } |
3896 | } | 4282 | } |
3897 | 4283 | ||
4284 | m_host.TaskInventory.LockItemsForRead(false); | ||
3898 | return count; | 4285 | return count; |
3899 | } | 4286 | } |
3900 | 4287 | ||
@@ -3903,16 +4290,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3903 | m_host.AddScriptLPS(1); | 4290 | m_host.AddScriptLPS(1); |
3904 | ArrayList keys = new ArrayList(); | 4291 | ArrayList keys = new ArrayList(); |
3905 | 4292 | ||
3906 | lock (m_host.TaskInventory) | 4293 | m_host.TaskInventory.LockItemsForRead(true); |
4294 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | ||
3907 | { | 4295 | { |
3908 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | 4296 | if (inv.Value.Type == type || type == -1) |
3909 | { | 4297 | { |
3910 | if (inv.Value.Type == type || type == -1) | 4298 | keys.Add(inv.Value.Name); |
3911 | { | ||
3912 | keys.Add(inv.Value.Name); | ||
3913 | } | ||
3914 | } | 4299 | } |
3915 | } | 4300 | } |
4301 | m_host.TaskInventory.LockItemsForRead(false); | ||
3916 | 4302 | ||
3917 | if (keys.Count == 0) | 4303 | if (keys.Count == 0) |
3918 | { | 4304 | { |
@@ -3949,25 +4335,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3949 | } | 4335 | } |
3950 | 4336 | ||
3951 | // move the first object found with this inventory name | 4337 | // move the first object found with this inventory name |
3952 | lock (m_host.TaskInventory) | 4338 | m_host.TaskInventory.LockItemsForRead(true); |
4339 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | ||
3953 | { | 4340 | { |
3954 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | 4341 | if (inv.Value.Name == inventory) |
3955 | { | 4342 | { |
3956 | if (inv.Value.Name == inventory) | 4343 | found = true; |
3957 | { | 4344 | objId = inv.Key; |
3958 | found = true; | 4345 | assetType = inv.Value.Type; |
3959 | objId = inv.Key; | 4346 | objName = inv.Value.Name; |
3960 | assetType = inv.Value.Type; | 4347 | break; |
3961 | objName = inv.Value.Name; | ||
3962 | break; | ||
3963 | } | ||
3964 | } | 4348 | } |
3965 | } | 4349 | } |
4350 | m_host.TaskInventory.LockItemsForRead(false); | ||
3966 | 4351 | ||
3967 | if (!found) | 4352 | if (!found) |
3968 | { | 4353 | { |
3969 | llSay(0, String.Format("Could not find object '{0}'", inventory)); | 4354 | llSay(0, String.Format("Could not find object '{0}'", inventory)); |
3970 | throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory)); | 4355 | return; |
4356 | // throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory)); | ||
3971 | } | 4357 | } |
3972 | 4358 | ||
3973 | // check if destination is an object | 4359 | // check if destination is an object |
@@ -3993,48 +4379,68 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3993 | return; | 4379 | return; |
3994 | } | 4380 | } |
3995 | } | 4381 | } |
4382 | |||
3996 | // destination is an avatar | 4383 | // destination is an avatar |
3997 | InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId); | 4384 | InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId); |
3998 | 4385 | ||
3999 | if (agentItem == null) | 4386 | if (agentItem == null) |
4000 | return; | 4387 | return; |
4001 | 4388 | ||
4002 | byte[] bucket = new byte[17]; | 4389 | byte[] bucket = new byte[1]; |
4003 | bucket[0] = (byte)assetType; | 4390 | bucket[0] = (byte)assetType; |
4004 | byte[] objBytes = agentItem.ID.GetBytes(); | 4391 | //byte[] objBytes = agentItem.ID.GetBytes(); |
4005 | Array.Copy(objBytes, 0, bucket, 1, 16); | 4392 | //Array.Copy(objBytes, 0, bucket, 1, 16); |
4006 | 4393 | ||
4007 | GridInstantMessage msg = new GridInstantMessage(World, | 4394 | GridInstantMessage msg = new GridInstantMessage(World, |
4008 | m_host.UUID, m_host.Name+", an object owned by "+ | 4395 | m_host.OwnerID, m_host.Name, destId, |
4009 | resolveName(m_host.OwnerID)+",", destId, | ||
4010 | (byte)InstantMessageDialog.TaskInventoryOffered, | 4396 | (byte)InstantMessageDialog.TaskInventoryOffered, |
4011 | false, objName+"\n"+m_host.Name+" is located at "+ | 4397 | false, objName+". "+m_host.Name+" is located at "+ |
4012 | World.RegionInfo.RegionName+" "+ | 4398 | World.RegionInfo.RegionName+" "+ |
4013 | m_host.AbsolutePosition.ToString(), | 4399 | m_host.AbsolutePosition.ToString(), |
4014 | agentItem.ID, true, m_host.AbsolutePosition, | 4400 | agentItem.ID, true, m_host.AbsolutePosition, |
4015 | bucket); | 4401 | bucket); |
4016 | if (m_TransferModule != null) | 4402 | |
4017 | m_TransferModule.SendInstantMessage(msg, delegate(bool success) {}); | 4403 | ScenePresence sp; |
4404 | |||
4405 | if (World.TryGetScenePresence(destId, out sp)) | ||
4406 | { | ||
4407 | sp.ControllingClient.SendInstantMessage(msg); | ||
4408 | } | ||
4409 | else | ||
4410 | { | ||
4411 | if (m_TransferModule != null) | ||
4412 | m_TransferModule.SendInstantMessage(msg, delegate(bool success) {}); | ||
4413 | } | ||
4414 | |||
4415 | //This delay should only occur when giving inventory to avatars. | ||
4018 | ScriptSleep(3000); | 4416 | ScriptSleep(3000); |
4019 | } | 4417 | } |
4020 | } | 4418 | } |
4021 | 4419 | ||
4420 | [DebuggerNonUserCode] | ||
4022 | public void llRemoveInventory(string name) | 4421 | public void llRemoveInventory(string name) |
4023 | { | 4422 | { |
4024 | m_host.AddScriptLPS(1); | 4423 | m_host.AddScriptLPS(1); |
4025 | 4424 | ||
4026 | lock (m_host.TaskInventory) | 4425 | List<TaskInventoryItem> inv; |
4426 | try | ||
4027 | { | 4427 | { |
4028 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | 4428 | m_host.TaskInventory.LockItemsForRead(true); |
4429 | inv = new List<TaskInventoryItem>(m_host.TaskInventory.Values); | ||
4430 | } | ||
4431 | finally | ||
4432 | { | ||
4433 | m_host.TaskInventory.LockItemsForRead(false); | ||
4434 | } | ||
4435 | foreach (TaskInventoryItem item in inv) | ||
4436 | { | ||
4437 | if (item.Name == name) | ||
4029 | { | 4438 | { |
4030 | if (item.Name == name) | 4439 | if (item.ItemID == m_itemID) |
4031 | { | 4440 | throw new ScriptDeleteException(); |
4032 | if (item.ItemID == m_itemID) | 4441 | else |
4033 | throw new ScriptDeleteException(); | 4442 | m_host.Inventory.RemoveInventoryItem(item.ItemID); |
4034 | else | 4443 | return; |
4035 | m_host.Inventory.RemoveInventoryItem(item.ItemID); | ||
4036 | return; | ||
4037 | } | ||
4038 | } | 4444 | } |
4039 | } | 4445 | } |
4040 | } | 4446 | } |
@@ -4069,112 +4475,122 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4069 | { | 4475 | { |
4070 | m_host.AddScriptLPS(1); | 4476 | m_host.AddScriptLPS(1); |
4071 | 4477 | ||
4072 | UUID uuid = (UUID)id; | 4478 | UUID uuid; |
4073 | PresenceInfo pinfo = null; | 4479 | if (UUID.TryParse(id, out uuid)) |
4074 | UserAccount account; | ||
4075 | |||
4076 | UserInfoCacheEntry ce; | ||
4077 | if (!m_userInfoCache.TryGetValue(uuid, out ce)) | ||
4078 | { | 4480 | { |
4079 | account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid); | 4481 | PresenceInfo pinfo = null; |
4080 | if (account == null) | 4482 | UserAccount account; |
4483 | |||
4484 | UserInfoCacheEntry ce; | ||
4485 | if (!m_userInfoCache.TryGetValue(uuid, out ce)) | ||
4081 | { | 4486 | { |
4082 | m_userInfoCache[uuid] = null; // Cache negative | 4487 | account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid); |
4083 | return UUID.Zero.ToString(); | 4488 | if (account == null) |
4084 | } | 4489 | { |
4490 | m_userInfoCache[uuid] = null; // Cache negative | ||
4491 | return UUID.Zero.ToString(); | ||
4492 | } | ||
4085 | 4493 | ||
4086 | 4494 | ||
4087 | PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); | 4495 | PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); |
4088 | if (pinfos != null && pinfos.Length > 0) | 4496 | if (pinfos != null && pinfos.Length > 0) |
4089 | { | ||
4090 | foreach (PresenceInfo p in pinfos) | ||
4091 | { | 4497 | { |
4092 | if (p.RegionID != UUID.Zero) | 4498 | foreach (PresenceInfo p in pinfos) |
4093 | { | 4499 | { |
4094 | pinfo = p; | 4500 | if (p.RegionID != UUID.Zero) |
4501 | { | ||
4502 | pinfo = p; | ||
4503 | } | ||
4095 | } | 4504 | } |
4096 | } | 4505 | } |
4097 | } | ||
4098 | 4506 | ||
4099 | ce = new UserInfoCacheEntry(); | 4507 | ce = new UserInfoCacheEntry(); |
4100 | ce.time = Util.EnvironmentTickCount(); | 4508 | ce.time = Util.EnvironmentTickCount(); |
4101 | ce.account = account; | 4509 | ce.account = account; |
4102 | ce.pinfo = pinfo; | 4510 | ce.pinfo = pinfo; |
4103 | } | 4511 | m_userInfoCache[uuid] = ce; |
4104 | else | 4512 | } |
4105 | { | 4513 | else |
4106 | if (ce == null) | 4514 | { |
4107 | return UUID.Zero.ToString(); | 4515 | if (ce == null) |
4516 | return UUID.Zero.ToString(); | ||
4108 | 4517 | ||
4109 | account = ce.account; | 4518 | account = ce.account; |
4110 | pinfo = ce.pinfo; | 4519 | pinfo = ce.pinfo; |
4111 | } | 4520 | } |
4112 | 4521 | ||
4113 | if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000) | 4522 | if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000) |
4114 | { | ||
4115 | PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); | ||
4116 | if (pinfos != null && pinfos.Length > 0) | ||
4117 | { | 4523 | { |
4118 | foreach (PresenceInfo p in pinfos) | 4524 | PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); |
4525 | if (pinfos != null && pinfos.Length > 0) | ||
4119 | { | 4526 | { |
4120 | if (p.RegionID != UUID.Zero) | 4527 | foreach (PresenceInfo p in pinfos) |
4121 | { | 4528 | { |
4122 | pinfo = p; | 4529 | if (p.RegionID != UUID.Zero) |
4530 | { | ||
4531 | pinfo = p; | ||
4532 | } | ||
4123 | } | 4533 | } |
4124 | } | 4534 | } |
4125 | } | 4535 | else |
4126 | else | 4536 | pinfo = null; |
4127 | pinfo = null; | ||
4128 | 4537 | ||
4129 | ce.time = Util.EnvironmentTickCount(); | 4538 | ce.time = Util.EnvironmentTickCount(); |
4130 | ce.pinfo = pinfo; | 4539 | ce.pinfo = pinfo; |
4131 | } | 4540 | } |
4132 | 4541 | ||
4133 | string reply = String.Empty; | 4542 | string reply = String.Empty; |
4134 | 4543 | ||
4135 | switch (data) | 4544 | switch (data) |
4136 | { | 4545 | { |
4137 | case 1: // DATA_ONLINE (0|1) | 4546 | case 1: // DATA_ONLINE (0|1) |
4138 | if (pinfo != null && pinfo.RegionID != UUID.Zero) | 4547 | if (pinfo != null && pinfo.RegionID != UUID.Zero) |
4139 | reply = "1"; | 4548 | reply = "1"; |
4140 | else | 4549 | else |
4141 | reply = "0"; | 4550 | reply = "0"; |
4142 | break; | 4551 | break; |
4143 | case 2: // DATA_NAME (First Last) | 4552 | case 2: // DATA_NAME (First Last) |
4144 | reply = account.FirstName + " " + account.LastName; | 4553 | reply = account.FirstName + " " + account.LastName; |
4145 | break; | 4554 | break; |
4146 | case 3: // DATA_BORN (YYYY-MM-DD) | 4555 | case 3: // DATA_BORN (YYYY-MM-DD) |
4147 | DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0); | 4556 | DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0); |
4148 | born = born.AddSeconds(account.Created); | 4557 | born = born.AddSeconds(account.Created); |
4149 | reply = born.ToString("yyyy-MM-dd"); | 4558 | reply = born.ToString("yyyy-MM-dd"); |
4150 | break; | 4559 | break; |
4151 | case 4: // DATA_RATING (0,0,0,0,0,0) | 4560 | case 4: // DATA_RATING (0,0,0,0,0,0) |
4152 | reply = "0,0,0,0,0,0"; | 4561 | reply = "0,0,0,0,0,0"; |
4153 | break; | 4562 | break; |
4154 | case 8: // DATA_PAYINFO (0|1|2|3) | 4563 | case 8: // DATA_PAYINFO (0|1|2|3) |
4155 | reply = "0"; | 4564 | reply = "0"; |
4156 | break; | 4565 | break; |
4157 | default: | 4566 | default: |
4158 | return UUID.Zero.ToString(); // Raise no event | 4567 | return UUID.Zero.ToString(); // Raise no event |
4159 | } | 4568 | } |
4160 | 4569 | ||
4161 | UUID rq = UUID.Random(); | 4570 | UUID rq = UUID.Random(); |
4162 | 4571 | ||
4163 | UUID tid = AsyncCommands. | 4572 | UUID tid = AsyncCommands. |
4164 | DataserverPlugin.RegisterRequest(m_localID, | 4573 | DataserverPlugin.RegisterRequest(m_localID, |
4165 | m_itemID, rq.ToString()); | 4574 | m_itemID, rq.ToString()); |
4166 | 4575 | ||
4167 | AsyncCommands. | 4576 | AsyncCommands. |
4168 | DataserverPlugin.DataserverReply(rq.ToString(), reply); | 4577 | DataserverPlugin.DataserverReply(rq.ToString(), reply); |
4169 | 4578 | ||
4170 | ScriptSleep(100); | 4579 | ScriptSleep(100); |
4171 | return tid.ToString(); | 4580 | return tid.ToString(); |
4581 | } | ||
4582 | else | ||
4583 | { | ||
4584 | ShoutError("Invalid UUID passed to llRequestAgentData."); | ||
4585 | } | ||
4586 | return ""; | ||
4172 | } | 4587 | } |
4173 | 4588 | ||
4174 | public LSL_String llRequestInventoryData(string name) | 4589 | public LSL_String llRequestInventoryData(string name) |
4175 | { | 4590 | { |
4176 | m_host.AddScriptLPS(1); | 4591 | m_host.AddScriptLPS(1); |
4177 | 4592 | ||
4593 | //Clone is thread safe | ||
4178 | TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); | 4594 | TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); |
4179 | 4595 | ||
4180 | foreach (TaskInventoryItem item in itemDictionary.Values) | 4596 | foreach (TaskInventoryItem item in itemDictionary.Values) |
@@ -4226,19 +4642,54 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4226 | if (UUID.TryParse(agent, out agentId)) | 4642 | if (UUID.TryParse(agent, out agentId)) |
4227 | { | 4643 | { |
4228 | ScenePresence presence = World.GetScenePresence(agentId); | 4644 | ScenePresence presence = World.GetScenePresence(agentId); |
4229 | if (presence != null) | 4645 | if (presence != null && presence.PresenceType != PresenceType.Npc) |
4230 | { | 4646 | { |
4647 | // agent must not be a god | ||
4648 | if (presence.UserLevel >= 200) return; | ||
4649 | |||
4231 | // agent must be over the owners land | 4650 | // agent must be over the owners land |
4232 | if (m_host.OwnerID == World.LandChannel.GetLandObject( | 4651 | if (m_host.OwnerID == World.LandChannel.GetLandObject( |
4233 | presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID) | 4652 | presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID) |
4234 | { | 4653 | { |
4235 | World.TeleportClientHome(agentId, presence.ControllingClient); | 4654 | if (!World.TeleportClientHome(agentId, presence.ControllingClient)) |
4655 | { | ||
4656 | // They can't be teleported home for some reason | ||
4657 | GridRegion regionInfo = World.GridService.GetRegionByUUID(UUID.Zero, new UUID("2b02daac-e298-42fa-9a75-f488d37896e6")); | ||
4658 | if (regionInfo != null) | ||
4659 | { | ||
4660 | World.RequestTeleportLocation( | ||
4661 | presence.ControllingClient, regionInfo.RegionHandle, new Vector3(128, 128, 23), Vector3.Zero, | ||
4662 | (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome)); | ||
4663 | } | ||
4664 | } | ||
4236 | } | 4665 | } |
4237 | } | 4666 | } |
4238 | } | 4667 | } |
4239 | ScriptSleep(5000); | 4668 | ScriptSleep(5000); |
4240 | } | 4669 | } |
4241 | 4670 | ||
4671 | public void llTeleportAgent(string agent, string simname, LSL_Vector pos, LSL_Vector lookAt) | ||
4672 | { | ||
4673 | m_host.AddScriptLPS(1); | ||
4674 | UUID agentId = new UUID(); | ||
4675 | if (UUID.TryParse(agent, out agentId)) | ||
4676 | { | ||
4677 | ScenePresence presence = World.GetScenePresence(agentId); | ||
4678 | if (presence != null && presence.PresenceType != PresenceType.Npc) | ||
4679 | { | ||
4680 | // agent must not be a god | ||
4681 | if (presence.UserLevel >= 200) return; | ||
4682 | |||
4683 | // agent must be over the owners land | ||
4684 | if (m_host.OwnerID == World.LandChannel.GetLandObject( | ||
4685 | presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID) | ||
4686 | { | ||
4687 | World.RequestTeleportLocation(presence.ControllingClient, simname, new Vector3((float)pos.x, (float)pos.y, (float)pos.z), new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z), (uint)TeleportFlags.ViaLocation); | ||
4688 | } | ||
4689 | } | ||
4690 | } | ||
4691 | } | ||
4692 | |||
4242 | public void llTextBox(string agent, string message, int chatChannel) | 4693 | public void llTextBox(string agent, string message, int chatChannel) |
4243 | { | 4694 | { |
4244 | IDialogModule dm = World.RequestModuleInterface<IDialogModule>(); | 4695 | IDialogModule dm = World.RequestModuleInterface<IDialogModule>(); |
@@ -4250,7 +4701,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4250 | UUID av = new UUID(); | 4701 | UUID av = new UUID(); |
4251 | if (!UUID.TryParse(agent,out av)) | 4702 | if (!UUID.TryParse(agent,out av)) |
4252 | { | 4703 | { |
4253 | LSLError("First parameter to llDialog needs to be a key"); | 4704 | //LSLError("First parameter to llDialog needs to be a key"); |
4254 | return; | 4705 | return; |
4255 | } | 4706 | } |
4256 | 4707 | ||
@@ -4287,17 +4738,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4287 | UUID soundId = UUID.Zero; | 4738 | UUID soundId = UUID.Zero; |
4288 | if (!UUID.TryParse(impact_sound, out soundId)) | 4739 | if (!UUID.TryParse(impact_sound, out soundId)) |
4289 | { | 4740 | { |
4290 | lock (m_host.TaskInventory) | 4741 | m_host.TaskInventory.LockItemsForRead(true); |
4742 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | ||
4291 | { | 4743 | { |
4292 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | 4744 | if (item.Type == (int)AssetType.Sound && item.Name == impact_sound) |
4293 | { | 4745 | { |
4294 | if (item.Type == (int)AssetType.Sound && item.Name == impact_sound) | 4746 | soundId = item.AssetID; |
4295 | { | 4747 | break; |
4296 | soundId = item.AssetID; | ||
4297 | break; | ||
4298 | } | ||
4299 | } | 4748 | } |
4300 | } | 4749 | } |
4750 | m_host.TaskInventory.LockItemsForRead(false); | ||
4301 | } | 4751 | } |
4302 | m_host.CollisionSound = soundId; | 4752 | m_host.CollisionSound = soundId; |
4303 | m_host.CollisionSoundVolume = (float)impact_volume; | 4753 | m_host.CollisionSoundVolume = (float)impact_volume; |
@@ -4337,6 +4787,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4337 | UUID partItemID; | 4787 | UUID partItemID; |
4338 | foreach (SceneObjectPart part in parts) | 4788 | foreach (SceneObjectPart part in parts) |
4339 | { | 4789 | { |
4790 | //Clone is thread safe | ||
4340 | TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone(); | 4791 | TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone(); |
4341 | 4792 | ||
4342 | foreach (TaskInventoryItem item in itemsDictionary.Values) | 4793 | foreach (TaskInventoryItem item in itemsDictionary.Values) |
@@ -4540,17 +4991,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4540 | 4991 | ||
4541 | m_host.AddScriptLPS(1); | 4992 | m_host.AddScriptLPS(1); |
4542 | 4993 | ||
4543 | lock (m_host.TaskInventory) | 4994 | m_host.TaskInventory.LockItemsForRead(true); |
4995 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | ||
4544 | { | 4996 | { |
4545 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | 4997 | if (item.Type == 10 && item.ItemID == m_itemID) |
4546 | { | 4998 | { |
4547 | if (item.Type == 10 && item.ItemID == m_itemID) | 4999 | result = item.Name!=null?item.Name:String.Empty; |
4548 | { | 5000 | break; |
4549 | result = item.Name != null ? item.Name : String.Empty; | ||
4550 | break; | ||
4551 | } | ||
4552 | } | 5001 | } |
4553 | } | 5002 | } |
5003 | m_host.TaskInventory.LockItemsForRead(false); | ||
4554 | 5004 | ||
4555 | return result; | 5005 | return result; |
4556 | } | 5006 | } |
@@ -4723,23 +5173,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4723 | { | 5173 | { |
4724 | m_host.AddScriptLPS(1); | 5174 | m_host.AddScriptLPS(1); |
4725 | 5175 | ||
4726 | lock (m_host.TaskInventory) | 5176 | m_host.TaskInventory.LockItemsForRead(true); |
5177 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | ||
4727 | { | 5178 | { |
4728 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | 5179 | if (inv.Value.Name == name) |
4729 | { | 5180 | { |
4730 | if (inv.Value.Name == name) | 5181 | if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) |
4731 | { | 5182 | { |
4732 | if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) | 5183 | m_host.TaskInventory.LockItemsForRead(false); |
4733 | { | 5184 | return inv.Value.AssetID.ToString(); |
4734 | return inv.Value.AssetID.ToString(); | 5185 | } |
4735 | } | 5186 | else |
4736 | else | 5187 | { |
4737 | { | 5188 | m_host.TaskInventory.LockItemsForRead(false); |
4738 | return UUID.Zero.ToString(); | 5189 | return UUID.Zero.ToString(); |
4739 | } | ||
4740 | } | 5190 | } |
4741 | } | 5191 | } |
4742 | } | 5192 | } |
5193 | m_host.TaskInventory.LockItemsForRead(false); | ||
4743 | 5194 | ||
4744 | return UUID.Zero.ToString(); | 5195 | return UUID.Zero.ToString(); |
4745 | } | 5196 | } |
@@ -4892,14 +5343,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4892 | { | 5343 | { |
4893 | m_host.AddScriptLPS(1); | 5344 | m_host.AddScriptLPS(1); |
4894 | 5345 | ||
4895 | if (src == null) | 5346 | return src.Length; |
4896 | { | ||
4897 | return 0; | ||
4898 | } | ||
4899 | else | ||
4900 | { | ||
4901 | return src.Length; | ||
4902 | } | ||
4903 | } | 5347 | } |
4904 | 5348 | ||
4905 | public LSL_Integer llList2Integer(LSL_List src, int index) | 5349 | public LSL_Integer llList2Integer(LSL_List src, int index) |
@@ -4945,7 +5389,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4945 | else if (src.Data[index] is LSL_Float) | 5389 | else if (src.Data[index] is LSL_Float) |
4946 | return Convert.ToDouble(((LSL_Float) src.Data[index]).value); | 5390 | return Convert.ToDouble(((LSL_Float) src.Data[index]).value); |
4947 | else if (src.Data[index] is LSL_String) | 5391 | else if (src.Data[index] is LSL_String) |
4948 | return Convert.ToDouble(((LSL_String) src.Data[index]).m_string); | 5392 | { |
5393 | string str = ((LSL_String) src.Data[index]).m_string; | ||
5394 | Match m = Regex.Match(str, "^\\s*(-?\\+?[,0-9]+\\.?[0-9]*)"); | ||
5395 | if (m != Match.Empty) | ||
5396 | { | ||
5397 | str = m.Value; | ||
5398 | double d = 0.0; | ||
5399 | if (!Double.TryParse(str, out d)) | ||
5400 | return 0.0; | ||
5401 | |||
5402 | return d; | ||
5403 | } | ||
5404 | return 0.0; | ||
5405 | } | ||
4949 | return Convert.ToDouble(src.Data[index]); | 5406 | return Convert.ToDouble(src.Data[index]); |
4950 | } | 5407 | } |
4951 | catch (FormatException) | 5408 | catch (FormatException) |
@@ -5218,7 +5675,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5218 | } | 5675 | } |
5219 | } | 5676 | } |
5220 | } | 5677 | } |
5221 | else { | 5678 | else |
5679 | { | ||
5222 | object[] array = new object[src.Length]; | 5680 | object[] array = new object[src.Length]; |
5223 | Array.Copy(src.Data, 0, array, 0, src.Length); | 5681 | Array.Copy(src.Data, 0, array, 0, src.Length); |
5224 | result = new LSL_List(array); | 5682 | result = new LSL_List(array); |
@@ -5325,7 +5783,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5325 | public LSL_Integer llGetRegionAgentCount() | 5783 | public LSL_Integer llGetRegionAgentCount() |
5326 | { | 5784 | { |
5327 | m_host.AddScriptLPS(1); | 5785 | m_host.AddScriptLPS(1); |
5328 | return new LSL_Integer(World.GetRootAgentCount()); | 5786 | |
5787 | int count = 0; | ||
5788 | World.ForEachRootScenePresence(delegate(ScenePresence sp) { | ||
5789 | count++; | ||
5790 | }); | ||
5791 | |||
5792 | return new LSL_Integer(count); | ||
5329 | } | 5793 | } |
5330 | 5794 | ||
5331 | public LSL_Vector llGetRegionCorner() | 5795 | public LSL_Vector llGetRegionCorner() |
@@ -5667,10 +6131,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5667 | m_host.AddScriptLPS(1); | 6131 | m_host.AddScriptLPS(1); |
5668 | 6132 | ||
5669 | List<SceneObjectPart> parts = GetLinkParts(linknumber); | 6133 | List<SceneObjectPart> parts = GetLinkParts(linknumber); |
5670 | 6134 | if (parts.Count > 0) | |
5671 | foreach (var part in parts) | ||
5672 | { | 6135 | { |
5673 | SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate); | 6136 | try |
6137 | { | ||
6138 | parts[0].ParentGroup.areUpdatesSuspended = true; | ||
6139 | foreach (var part in parts) | ||
6140 | { | ||
6141 | SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate); | ||
6142 | } | ||
6143 | } | ||
6144 | finally | ||
6145 | { | ||
6146 | parts[0].ParentGroup.areUpdatesSuspended = false; | ||
6147 | } | ||
5674 | } | 6148 | } |
5675 | } | 6149 | } |
5676 | 6150 | ||
@@ -5722,13 +6196,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5722 | 6196 | ||
5723 | if (m_host.OwnerID == land.LandData.OwnerID) | 6197 | if (m_host.OwnerID == land.LandData.OwnerID) |
5724 | { | 6198 | { |
5725 | World.TeleportClientHome(agentID, presence.ControllingClient); | 6199 | Vector3 pos = World.GetNearestAllowedPosition(presence, land); |
6200 | presence.TeleportWithMomentum(pos); | ||
6201 | presence.ControllingClient.SendAlertMessage("You have been ejected from this land"); | ||
5726 | } | 6202 | } |
5727 | } | 6203 | } |
5728 | } | 6204 | } |
5729 | ScriptSleep(5000); | 6205 | ScriptSleep(5000); |
5730 | } | 6206 | } |
5731 | 6207 | ||
6208 | public LSL_List llParseString2List(string str, LSL_List separators, LSL_List in_spacers) | ||
6209 | { | ||
6210 | return ParseString2List(str, separators, in_spacers, false); | ||
6211 | } | ||
6212 | |||
5732 | public LSL_Integer llOverMyLand(string id) | 6213 | public LSL_Integer llOverMyLand(string id) |
5733 | { | 6214 | { |
5734 | m_host.AddScriptLPS(1); | 6215 | m_host.AddScriptLPS(1); |
@@ -5793,8 +6274,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5793 | UUID agentId = new UUID(); | 6274 | UUID agentId = new UUID(); |
5794 | if (!UUID.TryParse(agent, out agentId)) | 6275 | if (!UUID.TryParse(agent, out agentId)) |
5795 | return new LSL_Integer(0); | 6276 | return new LSL_Integer(0); |
6277 | if (agentId == m_host.GroupID) | ||
6278 | return new LSL_Integer(1); | ||
5796 | ScenePresence presence = World.GetScenePresence(agentId); | 6279 | ScenePresence presence = World.GetScenePresence(agentId); |
5797 | if (presence == null || presence.IsChildAgent) // Return flase for child agents | 6280 | if (presence == null || presence.IsChildAgent) // Return false for child agents |
5798 | return new LSL_Integer(0); | 6281 | return new LSL_Integer(0); |
5799 | IClientAPI client = presence.ControllingClient; | 6282 | IClientAPI client = presence.ControllingClient; |
5800 | if (m_host.GroupID == client.ActiveGroupId) | 6283 | if (m_host.GroupID == client.ActiveGroupId) |
@@ -5929,7 +6412,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5929 | return m_host.ParentGroup.AttachmentPoint; | 6412 | return m_host.ParentGroup.AttachmentPoint; |
5930 | } | 6413 | } |
5931 | 6414 | ||
5932 | public LSL_Integer llGetFreeMemory() | 6415 | public virtual LSL_Integer llGetFreeMemory() |
5933 | { | 6416 | { |
5934 | m_host.AddScriptLPS(1); | 6417 | m_host.AddScriptLPS(1); |
5935 | // Make scripts designed for LSO happy | 6418 | // Make scripts designed for LSO happy |
@@ -6046,7 +6529,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6046 | SetParticleSystem(m_host, rules); | 6529 | SetParticleSystem(m_host, rules); |
6047 | } | 6530 | } |
6048 | 6531 | ||
6049 | private void SetParticleSystem(SceneObjectPart part, LSL_List rules) { | 6532 | private void SetParticleSystem(SceneObjectPart part, LSL_List rules) |
6533 | { | ||
6050 | 6534 | ||
6051 | 6535 | ||
6052 | if (rules.Length == 0) | 6536 | if (rules.Length == 0) |
@@ -6240,14 +6724,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6240 | 6724 | ||
6241 | protected UUID GetTaskInventoryItem(string name) | 6725 | protected UUID GetTaskInventoryItem(string name) |
6242 | { | 6726 | { |
6243 | lock (m_host.TaskInventory) | 6727 | m_host.TaskInventory.LockItemsForRead(true); |
6728 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | ||
6244 | { | 6729 | { |
6245 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | 6730 | if (inv.Value.Name == name) |
6246 | { | 6731 | { |
6247 | if (inv.Value.Name == name) | 6732 | m_host.TaskInventory.LockItemsForRead(false); |
6248 | return inv.Key; | 6733 | return inv.Key; |
6249 | } | 6734 | } |
6250 | } | 6735 | } |
6736 | m_host.TaskInventory.LockItemsForRead(false); | ||
6251 | 6737 | ||
6252 | return UUID.Zero; | 6738 | return UUID.Zero; |
6253 | } | 6739 | } |
@@ -6285,16 +6771,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6285 | if (folderID == UUID.Zero) | 6771 | if (folderID == UUID.Zero) |
6286 | return; | 6772 | return; |
6287 | 6773 | ||
6288 | byte[] bucket = new byte[17]; | 6774 | byte[] bucket = new byte[1]; |
6289 | bucket[0] = (byte)AssetType.Folder; | 6775 | bucket[0] = (byte)AssetType.Folder; |
6290 | byte[] objBytes = folderID.GetBytes(); | 6776 | //byte[] objBytes = folderID.GetBytes(); |
6291 | Array.Copy(objBytes, 0, bucket, 1, 16); | 6777 | //Array.Copy(objBytes, 0, bucket, 1, 16); |
6292 | 6778 | ||
6293 | GridInstantMessage msg = new GridInstantMessage(World, | 6779 | GridInstantMessage msg = new GridInstantMessage(World, |
6294 | m_host.UUID, m_host.Name+", an object owned by "+ | 6780 | m_host.OwnerID, m_host.Name, destID, |
6295 | resolveName(m_host.OwnerID)+",", destID, | 6781 | (byte)InstantMessageDialog.TaskInventoryOffered, |
6296 | (byte)InstantMessageDialog.InventoryOffered, | 6782 | false, category+". "+m_host.Name+" is located at "+ |
6297 | false, category+"\n"+m_host.Name+" is located at "+ | ||
6298 | World.RegionInfo.RegionName+" "+ | 6783 | World.RegionInfo.RegionName+" "+ |
6299 | m_host.AbsolutePosition.ToString(), | 6784 | m_host.AbsolutePosition.ToString(), |
6300 | folderID, true, m_host.AbsolutePosition, | 6785 | folderID, true, m_host.AbsolutePosition, |
@@ -6532,13 +7017,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6532 | UUID av = new UUID(); | 7017 | UUID av = new UUID(); |
6533 | if (!UUID.TryParse(avatar,out av)) | 7018 | if (!UUID.TryParse(avatar,out av)) |
6534 | { | 7019 | { |
6535 | LSLError("First parameter to llDialog needs to be a key"); | 7020 | //LSLError("First parameter to llDialog needs to be a key"); |
6536 | return; | 7021 | return; |
6537 | } | 7022 | } |
6538 | if (buttons.Length < 1) | 7023 | if (buttons.Length < 1) |
6539 | { | 7024 | { |
6540 | LSLError("No less than 1 button can be shown"); | 7025 | buttons.Add("OK"); |
6541 | return; | ||
6542 | } | 7026 | } |
6543 | if (buttons.Length > 12) | 7027 | if (buttons.Length > 12) |
6544 | { | 7028 | { |
@@ -6555,7 +7039,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6555 | } | 7039 | } |
6556 | if (buttons.Data[i].ToString().Length > 24) | 7040 | if (buttons.Data[i].ToString().Length > 24) |
6557 | { | 7041 | { |
6558 | LSLError("button label cannot be longer than 24 characters"); | 7042 | llWhisper(ScriptBaseClass.DEBUG_CHANNEL, "button label cannot be longer than 24 characters"); |
6559 | return; | 7043 | return; |
6560 | } | 7044 | } |
6561 | buts[i] = buttons.Data[i].ToString(); | 7045 | buts[i] = buttons.Data[i].ToString(); |
@@ -6614,22 +7098,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6614 | } | 7098 | } |
6615 | 7099 | ||
6616 | // copy the first script found with this inventory name | 7100 | // copy the first script found with this inventory name |
6617 | lock (m_host.TaskInventory) | 7101 | TaskInventoryItem scriptItem = null; |
7102 | m_host.TaskInventory.LockItemsForRead(true); | ||
7103 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | ||
6618 | { | 7104 | { |
6619 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | 7105 | if (inv.Value.Name == name) |
6620 | { | 7106 | { |
6621 | if (inv.Value.Name == name) | 7107 | // make sure the object is a script |
7108 | if (10 == inv.Value.Type) | ||
6622 | { | 7109 | { |
6623 | // make sure the object is a script | 7110 | found = true; |
6624 | if (10 == inv.Value.Type) | 7111 | srcId = inv.Key; |
6625 | { | 7112 | scriptItem = inv.Value; |
6626 | found = true; | 7113 | break; |
6627 | srcId = inv.Key; | ||
6628 | break; | ||
6629 | } | ||
6630 | } | 7114 | } |
6631 | } | 7115 | } |
6632 | } | 7116 | } |
7117 | m_host.TaskInventory.LockItemsForRead(false); | ||
6633 | 7118 | ||
6634 | if (!found) | 7119 | if (!found) |
6635 | { | 7120 | { |
@@ -6637,9 +7122,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6637 | return; | 7122 | return; |
6638 | } | 7123 | } |
6639 | 7124 | ||
6640 | // the rest of the permission checks are done in RezScript, so check the pin there as well | 7125 | SceneObjectPart dest = World.GetSceneObjectPart(destId); |
6641 | World.RezScriptFromPrim(srcId, m_host, destId, pin, running, start_param); | 7126 | if (dest != null) |
7127 | { | ||
7128 | if ((scriptItem.BasePermissions & (uint)PermissionMask.Transfer) != 0 || dest.ParentGroup.RootPart.OwnerID == m_host.ParentGroup.RootPart.OwnerID) | ||
7129 | { | ||
7130 | // the rest of the permission checks are done in RezScript, so check the pin there as well | ||
7131 | World.RezScriptFromPrim(srcId, m_host, destId, pin, running, start_param); | ||
6642 | 7132 | ||
7133 | if ((scriptItem.BasePermissions & (uint)PermissionMask.Copy) == 0) | ||
7134 | m_host.Inventory.RemoveInventoryItem(srcId); | ||
7135 | } | ||
7136 | } | ||
6643 | // this will cause the delay even if the script pin or permissions were wrong - seems ok | 7137 | // this will cause the delay even if the script pin or permissions were wrong - seems ok |
6644 | ScriptSleep(3000); | 7138 | ScriptSleep(3000); |
6645 | } | 7139 | } |
@@ -6702,19 +7196,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6702 | public LSL_String llMD5String(string src, int nonce) | 7196 | public LSL_String llMD5String(string src, int nonce) |
6703 | { | 7197 | { |
6704 | m_host.AddScriptLPS(1); | 7198 | m_host.AddScriptLPS(1); |
6705 | return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString())); | 7199 | return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString()), Encoding.UTF8); |
6706 | } | 7200 | } |
6707 | 7201 | ||
6708 | public LSL_String llSHA1String(string src) | 7202 | public LSL_String llSHA1String(string src) |
6709 | { | 7203 | { |
6710 | m_host.AddScriptLPS(1); | 7204 | m_host.AddScriptLPS(1); |
6711 | return Util.SHA1Hash(src).ToLower(); | 7205 | return Util.SHA1Hash(src, Encoding.UTF8).ToLower(); |
6712 | } | 7206 | } |
6713 | 7207 | ||
6714 | protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve) | 7208 | protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve) |
6715 | { | 7209 | { |
6716 | float tempFloat; // Use in float expressions below to avoid byte cast precision issues. | 7210 | float tempFloat; // Use in float expressions below to avoid byte cast precision issues. |
6717 | ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); | 7211 | ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); |
7212 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) | ||
7213 | return shapeBlock; | ||
6718 | 7214 | ||
6719 | if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT && | 7215 | if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT && |
6720 | holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE && | 7216 | holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE && |
@@ -6819,6 +7315,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6819 | // Prim type box, cylinder and prism. | 7315 | // Prim type box, cylinder and prism. |
6820 | protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector taper_b, LSL_Vector topshear, byte profileshape, byte pathcurve) | 7316 | protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector taper_b, LSL_Vector topshear, byte profileshape, byte pathcurve) |
6821 | { | 7317 | { |
7318 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) | ||
7319 | return; | ||
7320 | |||
6822 | float tempFloat; // Use in float expressions below to avoid byte cast precision issues. | 7321 | float tempFloat; // Use in float expressions below to avoid byte cast precision issues. |
6823 | ObjectShapePacket.ObjectDataBlock shapeBlock; | 7322 | ObjectShapePacket.ObjectDataBlock shapeBlock; |
6824 | 7323 | ||
@@ -6872,6 +7371,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6872 | // Prim type sphere. | 7371 | // Prim type sphere. |
6873 | protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte profileshape, byte pathcurve) | 7372 | protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte profileshape, byte pathcurve) |
6874 | { | 7373 | { |
7374 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) | ||
7375 | return; | ||
7376 | |||
6875 | ObjectShapePacket.ObjectDataBlock shapeBlock; | 7377 | ObjectShapePacket.ObjectDataBlock shapeBlock; |
6876 | 7378 | ||
6877 | shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve); | 7379 | shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve); |
@@ -6913,6 +7415,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6913 | // Prim type torus, tube and ring. | 7415 | // Prim type torus, tube and ring. |
6914 | protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector holesize, LSL_Vector topshear, LSL_Vector profilecut, LSL_Vector taper_a, float revolutions, float radiusoffset, float skew, byte profileshape, byte pathcurve) | 7416 | protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector holesize, LSL_Vector topshear, LSL_Vector profilecut, LSL_Vector taper_a, float revolutions, float radiusoffset, float skew, byte profileshape, byte pathcurve) |
6915 | { | 7417 | { |
7418 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) | ||
7419 | return; | ||
7420 | |||
6916 | float tempFloat; // Use in float expressions below to avoid byte cast precision issues. | 7421 | float tempFloat; // Use in float expressions below to avoid byte cast precision issues. |
6917 | ObjectShapePacket.ObjectDataBlock shapeBlock; | 7422 | ObjectShapePacket.ObjectDataBlock shapeBlock; |
6918 | 7423 | ||
@@ -7048,6 +7553,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7048 | // Prim type sculpt. | 7553 | // Prim type sculpt. |
7049 | protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type, byte pathcurve) | 7554 | protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type, byte pathcurve) |
7050 | { | 7555 | { |
7556 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) | ||
7557 | return; | ||
7558 | |||
7051 | ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); | 7559 | ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); |
7052 | UUID sculptId; | 7560 | UUID sculptId; |
7053 | 7561 | ||
@@ -7072,7 +7580,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7072 | type != (ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS | flag)) | 7580 | type != (ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS | flag)) |
7073 | { | 7581 | { |
7074 | // default | 7582 | // default |
7075 | type = (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE; | 7583 | type = type | (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE; |
7076 | } | 7584 | } |
7077 | 7585 | ||
7078 | part.Shape.SetSculptProperties((byte)type, sculptId); | 7586 | part.Shape.SetSculptProperties((byte)type, sculptId); |
@@ -7088,32 +7596,119 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7088 | ScriptSleep(200); | 7596 | ScriptSleep(200); |
7089 | } | 7597 | } |
7090 | 7598 | ||
7091 | public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules) | 7599 | public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules) |
7092 | { | 7600 | { |
7093 | m_host.AddScriptLPS(1); | 7601 | m_host.AddScriptLPS(1); |
7094 | 7602 | ||
7095 | setLinkPrimParams(linknumber, rules); | 7603 | setLinkPrimParams(linknumber, rules); |
7096 | |||
7097 | ScriptSleep(200); | ||
7098 | } | 7604 | } |
7099 | 7605 | ||
7100 | public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules) | 7606 | private void setLinkPrimParams(int linknumber, LSL_List rules) |
7101 | { | 7607 | { |
7102 | m_host.AddScriptLPS(1); | 7608 | List<SceneObjectPart> parts = GetLinkParts(linknumber); |
7609 | List<ScenePresence> avatars = GetLinkAvatars(linknumber); | ||
7610 | if (parts.Count>0) | ||
7611 | { | ||
7612 | try | ||
7613 | { | ||
7614 | parts[0].ParentGroup.areUpdatesSuspended = true; | ||
7615 | foreach (SceneObjectPart part in parts) | ||
7616 | SetPrimParams(part, rules); | ||
7617 | } | ||
7618 | finally | ||
7619 | { | ||
7620 | parts[0].ParentGroup.areUpdatesSuspended = false; | ||
7621 | } | ||
7622 | } | ||
7623 | if (avatars.Count > 0) | ||
7624 | { | ||
7625 | foreach (ScenePresence avatar in avatars) | ||
7626 | SetPrimParams(avatar, rules); | ||
7627 | } | ||
7628 | } | ||
7103 | 7629 | ||
7104 | setLinkPrimParams(linknumber, rules); | 7630 | public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules) |
7631 | { | ||
7632 | llSetLinkPrimitiveParamsFast(linknumber, rules); | ||
7633 | ScriptSleep(200); | ||
7105 | } | 7634 | } |
7106 | 7635 | ||
7107 | protected void setLinkPrimParams(int linknumber, LSL_List rules) | 7636 | protected void SetPrimParams(ScenePresence av, LSL_List rules) |
7108 | { | 7637 | { |
7109 | List<SceneObjectPart> parts = GetLinkParts(linknumber); | 7638 | //This is a special version of SetPrimParams to deal with avatars which are sat on the linkset. |
7639 | //We only support PRIM_POSITION and PRIM_ROTATION | ||
7110 | 7640 | ||
7111 | foreach (SceneObjectPart part in parts) | 7641 | int idx = 0; |
7112 | SetPrimParams(part, rules); | 7642 | |
7643 | while (idx < rules.Length) | ||
7644 | { | ||
7645 | int code = rules.GetLSLIntegerItem(idx++); | ||
7646 | |||
7647 | int remain = rules.Length - idx; | ||
7648 | |||
7649 | switch (code) | ||
7650 | { | ||
7651 | case (int)ScriptBaseClass.PRIM_POSITION: | ||
7652 | { | ||
7653 | if (remain < 1) | ||
7654 | return; | ||
7655 | LSL_Vector v; | ||
7656 | v = rules.GetVector3Item(idx++); | ||
7657 | |||
7658 | SceneObjectPart part = World.GetSceneObjectPart(av.ParentID); | ||
7659 | if (part == null) | ||
7660 | break; | ||
7661 | |||
7662 | LSL_Rotation localRot = ScriptBaseClass.ZERO_ROTATION; | ||
7663 | LSL_Vector localPos = ScriptBaseClass.ZERO_VECTOR; | ||
7664 | if (llGetLinkNumber() > 1) | ||
7665 | { | ||
7666 | localRot = llGetLocalRot(); | ||
7667 | localPos = llGetLocalPos(); | ||
7668 | } | ||
7669 | |||
7670 | v -= localPos; | ||
7671 | v /= localRot; | ||
7672 | |||
7673 | LSL_Vector sitOffset = (llRot2Up(new LSL_Rotation(av.Rotation.X, av.Rotation.Y, av.Rotation.Z, av.Rotation.W)) * av.Appearance.AvatarHeight * 0.02638f); | ||
7674 | |||
7675 | v = v + 2 * sitOffset; | ||
7676 | |||
7677 | av.OffsetPosition = new Vector3((float)v.x, (float)v.y, (float)v.z); | ||
7678 | av.SendAvatarDataToAllAgents(); | ||
7679 | |||
7680 | } | ||
7681 | break; | ||
7682 | |||
7683 | case (int)ScriptBaseClass.PRIM_ROTATION: | ||
7684 | { | ||
7685 | if (remain < 1) | ||
7686 | return; | ||
7687 | |||
7688 | LSL_Rotation localRot = ScriptBaseClass.ZERO_ROTATION; | ||
7689 | LSL_Vector localPos = ScriptBaseClass.ZERO_VECTOR; | ||
7690 | if (llGetLinkNumber() > 1) | ||
7691 | { | ||
7692 | localRot = llGetLocalRot(); | ||
7693 | localPos = llGetLocalPos(); | ||
7694 | } | ||
7695 | |||
7696 | LSL_Rotation r; | ||
7697 | r = rules.GetQuaternionItem(idx++); | ||
7698 | r = r * llGetRootRotation() / localRot; | ||
7699 | av.Rotation = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s); | ||
7700 | av.SendAvatarDataToAllAgents(); | ||
7701 | } | ||
7702 | break; | ||
7703 | } | ||
7704 | } | ||
7113 | } | 7705 | } |
7114 | 7706 | ||
7115 | protected void SetPrimParams(SceneObjectPart part, LSL_List rules) | 7707 | protected void SetPrimParams(SceneObjectPart part, LSL_List rules) |
7116 | { | 7708 | { |
7709 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) | ||
7710 | return; | ||
7711 | |||
7117 | int idx = 0; | 7712 | int idx = 0; |
7118 | 7713 | ||
7119 | bool positionChanged = false; | 7714 | bool positionChanged = false; |
@@ -7141,6 +7736,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7141 | currentPosition = GetSetPosTarget(part, v, currentPosition); | 7736 | currentPosition = GetSetPosTarget(part, v, currentPosition); |
7142 | 7737 | ||
7143 | break; | 7738 | break; |
7739 | case (int)ScriptBaseClass.PRIM_POS_LOCAL: | ||
7740 | if (remain < 1) | ||
7741 | return; | ||
7742 | |||
7743 | v=rules.GetVector3Item(idx++); | ||
7744 | positionChanged = true; | ||
7745 | currentPosition = GetSetPosTarget(part, v, currentPosition); | ||
7746 | |||
7747 | break; | ||
7144 | case (int)ScriptBaseClass.PRIM_SIZE: | 7748 | case (int)ScriptBaseClass.PRIM_SIZE: |
7145 | if (remain < 1) | 7749 | if (remain < 1) |
7146 | return; | 7750 | return; |
@@ -7507,7 +8111,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7507 | if (part.ParentGroup.RootPart == part) | 8111 | if (part.ParentGroup.RootPart == part) |
7508 | { | 8112 | { |
7509 | SceneObjectGroup parent = part.ParentGroup; | 8113 | SceneObjectGroup parent = part.ParentGroup; |
7510 | parent.UpdateGroupPosition(new Vector3((float)currentPosition.x, (float)currentPosition.y, (float)currentPosition.z)); | 8114 | Util.FireAndForget(delegate(object x) { |
8115 | parent.UpdateGroupPosition(new Vector3((float)currentPosition.x, (float)currentPosition.y, (float)currentPosition.z)); | ||
8116 | }); | ||
7511 | } | 8117 | } |
7512 | else | 8118 | else |
7513 | { | 8119 | { |
@@ -7518,6 +8124,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7518 | } | 8124 | } |
7519 | } | 8125 | } |
7520 | } | 8126 | } |
8127 | |||
8128 | if (positionChanged) | ||
8129 | { | ||
8130 | if (part.ParentGroup.RootPart == part) | ||
8131 | { | ||
8132 | SceneObjectGroup parent = part.ParentGroup; | ||
8133 | Util.FireAndForget(delegate(object x) { | ||
8134 | parent.UpdateGroupPosition(new Vector3((float)currentPosition.x, (float)currentPosition.y, (float)currentPosition.z)); | ||
8135 | }); | ||
8136 | } | ||
8137 | else | ||
8138 | { | ||
8139 | part.OffsetPosition = new Vector3((float)currentPosition.x, (float)currentPosition.y, (float)currentPosition.z); | ||
8140 | SceneObjectGroup parent = part.ParentGroup; | ||
8141 | parent.HasGroupChanged = true; | ||
8142 | parent.ScheduleGroupForTerseUpdate(); | ||
8143 | } | ||
8144 | } | ||
7521 | } | 8145 | } |
7522 | 8146 | ||
7523 | public LSL_String llStringToBase64(string str) | 8147 | public LSL_String llStringToBase64(string str) |
@@ -7678,13 +8302,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7678 | public LSL_Integer llGetNumberOfPrims() | 8302 | public LSL_Integer llGetNumberOfPrims() |
7679 | { | 8303 | { |
7680 | m_host.AddScriptLPS(1); | 8304 | m_host.AddScriptLPS(1); |
7681 | int avatarCount = 0; | 8305 | int avatarCount = m_host.ParentGroup.GetLinkedAvatars().Count; |
7682 | World.ForEachRootScenePresence(delegate(ScenePresence presence) | 8306 | |
7683 | { | ||
7684 | if (presence.ParentID != 0 && m_host.ParentGroup.HasChildPrim(presence.ParentID)) | ||
7685 | avatarCount++; | ||
7686 | }); | ||
7687 | |||
7688 | return m_host.ParentGroup.PrimCount + avatarCount; | 8307 | return m_host.ParentGroup.PrimCount + avatarCount; |
7689 | } | 8308 | } |
7690 | 8309 | ||
@@ -7700,55 +8319,98 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7700 | m_host.AddScriptLPS(1); | 8319 | m_host.AddScriptLPS(1); |
7701 | UUID objID = UUID.Zero; | 8320 | UUID objID = UUID.Zero; |
7702 | LSL_List result = new LSL_List(); | 8321 | LSL_List result = new LSL_List(); |
8322 | |||
8323 | // If the ID is not valid, return null result | ||
7703 | if (!UUID.TryParse(obj, out objID)) | 8324 | if (!UUID.TryParse(obj, out objID)) |
7704 | { | 8325 | { |
7705 | result.Add(new LSL_Vector()); | 8326 | result.Add(new LSL_Vector()); |
7706 | result.Add(new LSL_Vector()); | 8327 | result.Add(new LSL_Vector()); |
7707 | return result; | 8328 | return result; |
7708 | } | 8329 | } |
8330 | |||
8331 | // Check if this is an attached prim. If so, replace | ||
8332 | // the UUID with the avatar UUID and report it's bounding box | ||
8333 | SceneObjectPart part = World.GetSceneObjectPart(objID); | ||
8334 | if (part != null && part.ParentGroup.IsAttachment) | ||
8335 | objID = part.ParentGroup.AttachedAvatar; | ||
8336 | |||
8337 | // Find out if this is an avatar ID. If so, return it's box | ||
7709 | ScenePresence presence = World.GetScenePresence(objID); | 8338 | ScenePresence presence = World.GetScenePresence(objID); |
7710 | if (presence != null) | 8339 | if (presence != null) |
7711 | { | 8340 | { |
7712 | if (presence.ParentID == 0) // not sat on an object | 8341 | // As per LSL Wiki, there is no difference between sitting |
8342 | // and standing avatar since server 1.36 | ||
8343 | LSL_Vector lower; | ||
8344 | LSL_Vector upper; | ||
8345 | if (presence.Animator.Animations.DefaultAnimation.AnimID | ||
8346 | == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) | ||
7713 | { | 8347 | { |
7714 | LSL_Vector lower; | 8348 | // This is for ground sitting avatars |
7715 | LSL_Vector upper; | 8349 | float height = presence.Appearance.AvatarHeight / 2.66666667f; |
7716 | if (presence.Animator.Animations.DefaultAnimation.AnimID | 8350 | lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f); |
7717 | == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) | 8351 | upper = new LSL_Vector(0.3375f, 0.45f, 0.0f); |
7718 | { | ||
7719 | // This is for ground sitting avatars | ||
7720 | float height = presence.Appearance.AvatarHeight / 2.66666667f; | ||
7721 | lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f); | ||
7722 | upper = new LSL_Vector(0.3375f, 0.45f, 0.0f); | ||
7723 | } | ||
7724 | else | ||
7725 | { | ||
7726 | // This is for standing/flying avatars | ||
7727 | float height = presence.Appearance.AvatarHeight / 2.0f; | ||
7728 | lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f); | ||
7729 | upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f); | ||
7730 | } | ||
7731 | result.Add(lower); | ||
7732 | result.Add(upper); | ||
7733 | return result; | ||
7734 | } | 8352 | } |
7735 | else | 8353 | else |
7736 | { | 8354 | { |
7737 | // sitting on an object so we need the bounding box of that | 8355 | // This is for standing/flying avatars |
7738 | // which should include the avatar so set the UUID to the | 8356 | float height = presence.Appearance.AvatarHeight / 2.0f; |
7739 | // UUID of the object the avatar is sat on and allow it to fall through | 8357 | lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f); |
7740 | // to processing an object | 8358 | upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f); |
7741 | SceneObjectPart p = World.GetSceneObjectPart(presence.ParentID); | ||
7742 | objID = p.UUID; | ||
7743 | } | 8359 | } |
8360 | |||
8361 | // Adjust to the documented error offsets (see LSL Wiki) | ||
8362 | lower += new LSL_Vector(0.05f, 0.05f, 0.05f); | ||
8363 | upper -= new LSL_Vector(0.05f, 0.05f, 0.05f); | ||
8364 | |||
8365 | if (lower.x > upper.x) | ||
8366 | lower.x = upper.x; | ||
8367 | if (lower.y > upper.y) | ||
8368 | lower.y = upper.y; | ||
8369 | if (lower.z > upper.z) | ||
8370 | lower.z = upper.z; | ||
8371 | |||
8372 | result.Add(lower); | ||
8373 | result.Add(upper); | ||
8374 | return result; | ||
7744 | } | 8375 | } |
7745 | SceneObjectPart part = World.GetSceneObjectPart(objID); | 8376 | |
8377 | part = World.GetSceneObjectPart(objID); | ||
7746 | // Currently only works for single prims without a sitting avatar | 8378 | // Currently only works for single prims without a sitting avatar |
7747 | if (part != null) | 8379 | if (part != null) |
7748 | { | 8380 | { |
7749 | Vector3 halfSize = part.Scale / 2.0f; | 8381 | float minX; |
7750 | LSL_Vector lower = new LSL_Vector(halfSize.X * -1.0f, halfSize.Y * -1.0f, halfSize.Z * -1.0f); | 8382 | float maxX; |
7751 | LSL_Vector upper = new LSL_Vector(halfSize.X, halfSize.Y, halfSize.Z); | 8383 | float minY; |
8384 | float maxY; | ||
8385 | float minZ; | ||
8386 | float maxZ; | ||
8387 | |||
8388 | // This BBox is in sim coordinates, with the offset being | ||
8389 | // a contained point. | ||
8390 | Vector3[] offsets = Scene.GetCombinedBoundingBox(new List<SceneObjectGroup> { part.ParentGroup }, | ||
8391 | out minX, out maxX, out minY, out maxY, out minZ, out maxZ); | ||
8392 | |||
8393 | minX -= offsets[0].X; | ||
8394 | maxX -= offsets[0].X; | ||
8395 | minY -= offsets[0].Y; | ||
8396 | maxY -= offsets[0].Y; | ||
8397 | minZ -= offsets[0].Z; | ||
8398 | maxZ -= offsets[0].Z; | ||
8399 | |||
8400 | LSL_Vector lower; | ||
8401 | LSL_Vector upper; | ||
8402 | |||
8403 | // Adjust to the documented error offsets (see LSL Wiki) | ||
8404 | lower = new LSL_Vector(minX + 0.05f, minY + 0.05f, minZ + 0.05f); | ||
8405 | upper = new LSL_Vector(maxX - 0.05f, maxY - 0.05f, maxZ - 0.05f); | ||
8406 | |||
8407 | if (lower.x > upper.x) | ||
8408 | lower.x = upper.x; | ||
8409 | if (lower.y > upper.y) | ||
8410 | lower.y = upper.y; | ||
8411 | if (lower.z > upper.z) | ||
8412 | lower.z = upper.z; | ||
8413 | |||
7752 | result.Add(lower); | 8414 | result.Add(lower); |
7753 | result.Add(upper); | 8415 | result.Add(upper); |
7754 | return result; | 8416 | return result; |
@@ -7828,13 +8490,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7828 | LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X, | 8490 | LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X, |
7829 | part.AbsolutePosition.Y, | 8491 | part.AbsolutePosition.Y, |
7830 | part.AbsolutePosition.Z); | 8492 | part.AbsolutePosition.Z); |
7831 | // For some reason, the part.AbsolutePosition.* values do not change if the | ||
7832 | // linkset is rotated; they always reflect the child prim's world position | ||
7833 | // as though the linkset is unrotated. This is incompatible behavior with SL's | ||
7834 | // implementation, so will break scripts imported from there (not to mention it | ||
7835 | // makes it more difficult to determine a child prim's actual inworld position). | ||
7836 | if (part.ParentID != 0) | ||
7837 | v = ((v - llGetRootPosition()) * llGetRootRotation()) + llGetRootPosition(); | ||
7838 | res.Add(v); | 8493 | res.Add(v); |
7839 | break; | 8494 | break; |
7840 | 8495 | ||
@@ -8005,56 +8660,92 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8005 | case (int)ScriptBaseClass.PRIM_BUMP_SHINY: | 8660 | case (int)ScriptBaseClass.PRIM_BUMP_SHINY: |
8006 | if (remain < 1) | 8661 | if (remain < 1) |
8007 | return res; | 8662 | return res; |
8008 | 8663 | face = (int)rules.GetLSLIntegerItem(idx++); | |
8009 | face=(int)rules.GetLSLIntegerItem(idx++); | ||
8010 | 8664 | ||
8011 | tex = part.Shape.Textures; | 8665 | tex = part.Shape.Textures; |
8666 | int shiny; | ||
8012 | if (face == ScriptBaseClass.ALL_SIDES) | 8667 | if (face == ScriptBaseClass.ALL_SIDES) |
8013 | { | 8668 | { |
8014 | for (face = 0; face < GetNumberOfSides(part); face++) | 8669 | for (face = 0; face < GetNumberOfSides(part); face++) |
8015 | { | 8670 | { |
8016 | Primitive.TextureEntryFace texface = tex.GetFace((uint)face); | 8671 | Shininess shinyness = tex.GetFace((uint)face).Shiny; |
8017 | // Convert Shininess to PRIM_SHINY_* | 8672 | if (shinyness == Shininess.High) |
8018 | res.Add(new LSL_Integer((uint)texface.Shiny >> 6)); | 8673 | { |
8019 | // PRIM_BUMP_* | 8674 | shiny = ScriptBaseClass.PRIM_SHINY_HIGH; |
8020 | res.Add(new LSL_Integer((int)texface.Bump)); | 8675 | } |
8676 | else if (shinyness == Shininess.Medium) | ||
8677 | { | ||
8678 | shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM; | ||
8679 | } | ||
8680 | else if (shinyness == Shininess.Low) | ||
8681 | { | ||
8682 | shiny = ScriptBaseClass.PRIM_SHINY_LOW; | ||
8683 | } | ||
8684 | else | ||
8685 | { | ||
8686 | shiny = ScriptBaseClass.PRIM_SHINY_NONE; | ||
8687 | } | ||
8688 | res.Add(new LSL_Integer(shiny)); | ||
8689 | res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump)); | ||
8021 | } | 8690 | } |
8022 | } | 8691 | } |
8023 | else | 8692 | else |
8024 | { | 8693 | { |
8025 | if (face >= 0 && face < GetNumberOfSides(part)) | 8694 | Shininess shinyness = tex.GetFace((uint)face).Shiny; |
8695 | if (shinyness == Shininess.High) | ||
8026 | { | 8696 | { |
8027 | Primitive.TextureEntryFace texface = tex.GetFace((uint)face); | 8697 | shiny = ScriptBaseClass.PRIM_SHINY_HIGH; |
8028 | // Convert Shininess to PRIM_SHINY_* | ||
8029 | res.Add(new LSL_Integer((uint)texface.Shiny >> 6)); | ||
8030 | // PRIM_BUMP_* | ||
8031 | res.Add(new LSL_Integer((int)texface.Bump)); | ||
8032 | } | 8698 | } |
8699 | else if (shinyness == Shininess.Medium) | ||
8700 | { | ||
8701 | shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM; | ||
8702 | } | ||
8703 | else if (shinyness == Shininess.Low) | ||
8704 | { | ||
8705 | shiny = ScriptBaseClass.PRIM_SHINY_LOW; | ||
8706 | } | ||
8707 | else | ||
8708 | { | ||
8709 | shiny = ScriptBaseClass.PRIM_SHINY_NONE; | ||
8710 | } | ||
8711 | res.Add(new LSL_Integer(shiny)); | ||
8712 | res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump)); | ||
8033 | } | 8713 | } |
8034 | break; | 8714 | break; |
8035 | 8715 | ||
8036 | case (int)ScriptBaseClass.PRIM_FULLBRIGHT: | 8716 | case (int)ScriptBaseClass.PRIM_FULLBRIGHT: |
8037 | if (remain < 1) | 8717 | if (remain < 1) |
8038 | return res; | 8718 | return res; |
8039 | 8719 | face = (int)rules.GetLSLIntegerItem(idx++); | |
8040 | face=(int)rules.GetLSLIntegerItem(idx++); | ||
8041 | 8720 | ||
8042 | tex = part.Shape.Textures; | 8721 | tex = part.Shape.Textures; |
8722 | int fullbright; | ||
8043 | if (face == ScriptBaseClass.ALL_SIDES) | 8723 | if (face == ScriptBaseClass.ALL_SIDES) |
8044 | { | 8724 | { |
8045 | for (face = 0; face < GetNumberOfSides(part); face++) | 8725 | for (face = 0; face < GetNumberOfSides(part); face++) |
8046 | { | 8726 | { |
8047 | Primitive.TextureEntryFace texface = tex.GetFace((uint)face); | 8727 | if (tex.GetFace((uint)face).Fullbright == true) |
8048 | res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0)); | 8728 | { |
8729 | fullbright = ScriptBaseClass.TRUE; | ||
8730 | } | ||
8731 | else | ||
8732 | { | ||
8733 | fullbright = ScriptBaseClass.FALSE; | ||
8734 | } | ||
8735 | res.Add(new LSL_Integer(fullbright)); | ||
8049 | } | 8736 | } |
8050 | } | 8737 | } |
8051 | else | 8738 | else |
8052 | { | 8739 | { |
8053 | if (face >= 0 && face < GetNumberOfSides(part)) | 8740 | if (tex.GetFace((uint)face).Fullbright == true) |
8054 | { | 8741 | { |
8055 | Primitive.TextureEntryFace texface = tex.GetFace((uint)face); | 8742 | fullbright = ScriptBaseClass.TRUE; |
8056 | res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0)); | ||
8057 | } | 8743 | } |
8744 | else | ||
8745 | { | ||
8746 | fullbright = ScriptBaseClass.FALSE; | ||
8747 | } | ||
8748 | res.Add(new LSL_Integer(fullbright)); | ||
8058 | } | 8749 | } |
8059 | break; | 8750 | break; |
8060 | 8751 | ||
@@ -8076,27 +8767,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8076 | break; | 8767 | break; |
8077 | 8768 | ||
8078 | case (int)ScriptBaseClass.PRIM_TEXGEN: | 8769 | case (int)ScriptBaseClass.PRIM_TEXGEN: |
8770 | // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR) | ||
8079 | if (remain < 1) | 8771 | if (remain < 1) |
8080 | return res; | 8772 | return res; |
8081 | 8773 | face = (int)rules.GetLSLIntegerItem(idx++); | |
8082 | face=(int)rules.GetLSLIntegerItem(idx++); | ||
8083 | 8774 | ||
8084 | tex = part.Shape.Textures; | 8775 | tex = part.Shape.Textures; |
8085 | if (face == ScriptBaseClass.ALL_SIDES) | 8776 | if (face == ScriptBaseClass.ALL_SIDES) |
8086 | { | 8777 | { |
8087 | for (face = 0; face < GetNumberOfSides(part); face++) | 8778 | for (face = 0; face < GetNumberOfSides(part); face++) |
8088 | { | 8779 | { |
8089 | MappingType texgen = tex.GetFace((uint)face).TexMapType; | 8780 | if (tex.GetFace((uint)face).TexMapType == MappingType.Planar) |
8090 | // Convert MappingType to PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR etc. | 8781 | { |
8091 | res.Add(new LSL_Integer((uint)texgen >> 1)); | 8782 | res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR)); |
8783 | } | ||
8784 | else | ||
8785 | { | ||
8786 | res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT)); | ||
8787 | } | ||
8092 | } | 8788 | } |
8093 | } | 8789 | } |
8094 | else | 8790 | else |
8095 | { | 8791 | { |
8096 | if (face >= 0 && face < GetNumberOfSides(part)) | 8792 | if (tex.GetFace((uint)face).TexMapType == MappingType.Planar) |
8793 | { | ||
8794 | res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR)); | ||
8795 | } | ||
8796 | else | ||
8097 | { | 8797 | { |
8098 | MappingType texgen = tex.GetFace((uint)face).TexMapType; | 8798 | res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT)); |
8099 | res.Add(new LSL_Integer((uint)texgen >> 1)); | ||
8100 | } | 8799 | } |
8101 | } | 8800 | } |
8102 | break; | 8801 | break; |
@@ -8119,28 +8818,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8119 | case (int)ScriptBaseClass.PRIM_GLOW: | 8818 | case (int)ScriptBaseClass.PRIM_GLOW: |
8120 | if (remain < 1) | 8819 | if (remain < 1) |
8121 | return res; | 8820 | return res; |
8122 | 8821 | face = (int)rules.GetLSLIntegerItem(idx++); | |
8123 | face=(int)rules.GetLSLIntegerItem(idx++); | ||
8124 | 8822 | ||
8125 | tex = part.Shape.Textures; | 8823 | tex = part.Shape.Textures; |
8824 | float primglow; | ||
8126 | if (face == ScriptBaseClass.ALL_SIDES) | 8825 | if (face == ScriptBaseClass.ALL_SIDES) |
8127 | { | 8826 | { |
8128 | for (face = 0; face < GetNumberOfSides(part); face++) | 8827 | for (face = 0; face < GetNumberOfSides(part); face++) |
8129 | { | 8828 | { |
8130 | Primitive.TextureEntryFace texface = tex.GetFace((uint)face); | 8829 | primglow = tex.GetFace((uint)face).Glow; |
8131 | res.Add(new LSL_Float(texface.Glow)); | 8830 | res.Add(new LSL_Float(primglow)); |
8132 | } | 8831 | } |
8133 | } | 8832 | } |
8134 | else | 8833 | else |
8135 | { | 8834 | { |
8136 | if (face >= 0 && face < GetNumberOfSides(part)) | 8835 | primglow = tex.GetFace((uint)face).Glow; |
8137 | { | 8836 | res.Add(new LSL_Float(primglow)); |
8138 | Primitive.TextureEntryFace texface = tex.GetFace((uint)face); | ||
8139 | res.Add(new LSL_Float(texface.Glow)); | ||
8140 | } | ||
8141 | } | 8837 | } |
8142 | break; | 8838 | break; |
8143 | |||
8144 | case (int)ScriptBaseClass.PRIM_TEXT: | 8839 | case (int)ScriptBaseClass.PRIM_TEXT: |
8145 | Color4 textColor = part.GetTextColor(); | 8840 | Color4 textColor = part.GetTextColor(); |
8146 | res.Add(new LSL_String(part.Text)); | 8841 | res.Add(new LSL_String(part.Text)); |
@@ -8752,8 +9447,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8752 | // The function returns an ordered list | 9447 | // The function returns an ordered list |
8753 | // representing the tokens found in the supplied | 9448 | // representing the tokens found in the supplied |
8754 | // sources string. If two successive tokenizers | 9449 | // sources string. If two successive tokenizers |
8755 | // are encountered, then a NULL entry is added | 9450 | // are encountered, then a null-string entry is |
8756 | // to the list. | 9451 | // added to the list. |
8757 | // | 9452 | // |
8758 | // It is a precondition that the source and | 9453 | // It is a precondition that the source and |
8759 | // toekizer lisst are non-null. If they are null, | 9454 | // toekizer lisst are non-null. If they are null, |
@@ -8761,7 +9456,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8761 | // while their lengths are being determined. | 9456 | // while their lengths are being determined. |
8762 | // | 9457 | // |
8763 | // A small amount of working memoryis required | 9458 | // A small amount of working memoryis required |
8764 | // of approximately 8*#tokenizers. | 9459 | // of approximately 8*#tokenizers + 8*srcstrlen. |
8765 | // | 9460 | // |
8766 | // There are many ways in which this function | 9461 | // There are many ways in which this function |
8767 | // can be implemented, this implementation is | 9462 | // can be implemented, this implementation is |
@@ -8777,155 +9472,124 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8777 | // and eliminates redundant tokenizers as soon | 9472 | // and eliminates redundant tokenizers as soon |
8778 | // as is possible. | 9473 | // as is possible. |
8779 | // | 9474 | // |
8780 | // The implementation tries to avoid any copying | 9475 | // The implementation tries to minimize temporary |
8781 | // of arrays or other objects. | 9476 | // garbage generation. |
8782 | // </remarks> | 9477 | // </remarks> |
8783 | 9478 | ||
8784 | private LSL_List ParseString(string src, LSL_List separators, LSL_List spacers, bool keepNulls) | 9479 | public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers) |
8785 | { | 9480 | { |
8786 | int beginning = 0; | 9481 | return ParseString2List(src, separators, spacers, true); |
8787 | int srclen = src.Length; | 9482 | } |
8788 | int seplen = separators.Length; | ||
8789 | object[] separray = separators.Data; | ||
8790 | int spclen = spacers.Length; | ||
8791 | object[] spcarray = spacers.Data; | ||
8792 | int mlen = seplen+spclen; | ||
8793 | |||
8794 | int[] offset = new int[mlen+1]; | ||
8795 | bool[] active = new bool[mlen]; | ||
8796 | |||
8797 | int best; | ||
8798 | int j; | ||
8799 | |||
8800 | // Initial capacity reduces resize cost | ||
8801 | 9483 | ||
8802 | LSL_List tokens = new LSL_List(); | 9484 | private LSL_List ParseString2List(string src, LSL_List separators, LSL_List spacers, bool keepNulls) |
9485 | { | ||
9486 | int srclen = src.Length; | ||
9487 | int seplen = separators.Length; | ||
9488 | object[] separray = separators.Data; | ||
9489 | int spclen = spacers.Length; | ||
9490 | object[] spcarray = spacers.Data; | ||
9491 | int dellen = 0; | ||
9492 | string[] delarray = new string[seplen+spclen]; | ||
8803 | 9493 | ||
8804 | // All entries are initially valid | 9494 | int outlen = 0; |
9495 | string[] outarray = new string[srclen*2+1]; | ||
8805 | 9496 | ||
8806 | for (int i = 0; i < mlen; i++) | 9497 | int i, j; |
8807 | active[i] = true; | 9498 | string d; |
8808 | 9499 | ||
8809 | offset[mlen] = srclen; | 9500 | m_host.AddScriptLPS(1); |
8810 | 9501 | ||
8811 | while (beginning < srclen) | 9502 | /* |
9503 | * Convert separator and spacer lists to C# strings. | ||
9504 | * Also filter out null strings so we don't hang. | ||
9505 | */ | ||
9506 | for (i = 0; i < seplen; i ++) | ||
8812 | { | 9507 | { |
9508 | d = separray[i].ToString(); | ||
9509 | if (d.Length > 0) | ||
9510 | { | ||
9511 | delarray[dellen++] = d; | ||
9512 | } | ||
9513 | } | ||
9514 | seplen = dellen; | ||
8813 | 9515 | ||
8814 | best = mlen; // as bad as it gets | 9516 | for (i = 0; i < spclen; i ++) |
9517 | { | ||
9518 | d = spcarray[i].ToString(); | ||
9519 | if (d.Length > 0) | ||
9520 | { | ||
9521 | delarray[dellen++] = d; | ||
9522 | } | ||
9523 | } | ||
8815 | 9524 | ||
8816 | // Scan for separators | 9525 | /* |
9526 | * Scan through source string from beginning to end. | ||
9527 | */ | ||
9528 | for (i = 0;;) | ||
9529 | { | ||
8817 | 9530 | ||
8818 | for (j = 0; j < seplen; j++) | 9531 | /* |
9532 | * Find earliest delimeter in src starting at i (if any). | ||
9533 | */ | ||
9534 | int earliestDel = -1; | ||
9535 | int earliestSrc = srclen; | ||
9536 | string earliestStr = null; | ||
9537 | for (j = 0; j < dellen; j ++) | ||
8819 | { | 9538 | { |
8820 | if (separray[j].ToString() == String.Empty) | 9539 | d = delarray[j]; |
8821 | active[j] = false; | 9540 | if (d != null) |
8822 | |||
8823 | if (active[j]) | ||
8824 | { | 9541 | { |
8825 | // scan all of the markers | 9542 | int index = src.IndexOf(d, i); |
8826 | if ((offset[j] = src.IndexOf(separray[j].ToString(), beginning)) == -1) | 9543 | if (index < 0) |
8827 | { | 9544 | { |
8828 | // not present at all | 9545 | delarray[j] = null; // delim nowhere in src, don't check it anymore |
8829 | active[j] = false; | ||
8830 | } | 9546 | } |
8831 | else | 9547 | else if (index < earliestSrc) |
8832 | { | 9548 | { |
8833 | // present and correct | 9549 | earliestSrc = index; // where delimeter starts in source string |
8834 | if (offset[j] < offset[best]) | 9550 | earliestDel = j; // where delimeter is in delarray[] |
8835 | { | 9551 | earliestStr = d; // the delimeter string from delarray[] |
8836 | // closest so far | 9552 | if (index == i) break; // can't do any better than found at beg of string |
8837 | best = j; | ||
8838 | if (offset[best] == beginning) | ||
8839 | break; | ||
8840 | } | ||
8841 | } | 9553 | } |
8842 | } | 9554 | } |
8843 | } | 9555 | } |
8844 | 9556 | ||
8845 | // Scan for spacers | 9557 | /* |
8846 | 9558 | * Output source string starting at i through start of earliest delimeter. | |
8847 | if (offset[best] != beginning) | 9559 | */ |
9560 | if (keepNulls || (earliestSrc > i)) | ||
8848 | { | 9561 | { |
8849 | for (j = seplen; (j < mlen) && (offset[best] > beginning); j++) | 9562 | outarray[outlen++] = src.Substring(i, earliestSrc - i); |
8850 | { | ||
8851 | if (spcarray[j-seplen].ToString() == String.Empty) | ||
8852 | active[j] = false; | ||
8853 | |||
8854 | if (active[j]) | ||
8855 | { | ||
8856 | // scan all of the markers | ||
8857 | if ((offset[j] = src.IndexOf(spcarray[j-seplen].ToString(), beginning)) == -1) | ||
8858 | { | ||
8859 | // not present at all | ||
8860 | active[j] = false; | ||
8861 | } | ||
8862 | else | ||
8863 | { | ||
8864 | // present and correct | ||
8865 | if (offset[j] < offset[best]) | ||
8866 | { | ||
8867 | // closest so far | ||
8868 | best = j; | ||
8869 | } | ||
8870 | } | ||
8871 | } | ||
8872 | } | ||
8873 | } | 9563 | } |
8874 | 9564 | ||
8875 | // This is the normal exit from the scanning loop | 9565 | /* |
9566 | * If no delimeter found at or after i, we're done scanning. | ||
9567 | */ | ||
9568 | if (earliestDel < 0) break; | ||
8876 | 9569 | ||
8877 | if (best == mlen) | 9570 | /* |
9571 | * If delimeter was a spacer, output the spacer. | ||
9572 | */ | ||
9573 | if (earliestDel >= seplen) | ||
8878 | { | 9574 | { |
8879 | // no markers were found on this pass | 9575 | outarray[outlen++] = earliestStr; |
8880 | // so we're pretty much done | ||
8881 | if ((keepNulls) || ((!keepNulls) && (srclen - beginning) > 0)) | ||
8882 | tokens.Add(new LSL_String(src.Substring(beginning, srclen - beginning))); | ||
8883 | break; | ||
8884 | } | 9576 | } |
8885 | 9577 | ||
8886 | // Otherwise we just add the newly delimited token | 9578 | /* |
8887 | // and recalculate where the search should continue. | 9579 | * Look at rest of src string following delimeter. |
8888 | if ((keepNulls) || ((!keepNulls) && (offset[best] - beginning) > 0)) | 9580 | */ |
8889 | tokens.Add(new LSL_String(src.Substring(beginning,offset[best]-beginning))); | 9581 | i = earliestSrc + earliestStr.Length; |
8890 | |||
8891 | if (best < seplen) | ||
8892 | { | ||
8893 | beginning = offset[best] + (separray[best].ToString()).Length; | ||
8894 | } | ||
8895 | else | ||
8896 | { | ||
8897 | beginning = offset[best] + (spcarray[best - seplen].ToString()).Length; | ||
8898 | string str = spcarray[best - seplen].ToString(); | ||
8899 | if ((keepNulls) || ((!keepNulls) && (str.Length > 0))) | ||
8900 | tokens.Add(new LSL_String(str)); | ||
8901 | } | ||
8902 | } | 9582 | } |
8903 | 9583 | ||
8904 | // This an awkward an not very intuitive boundary case. If the | 9584 | /* |
8905 | // last substring is a tokenizer, then there is an implied trailing | 9585 | * Make up an exact-sized output array suitable for an LSL_List object. |
8906 | // null list entry. Hopefully the single comparison will not be too | 9586 | */ |
8907 | // arduous. Alternatively the 'break' could be replced with a return | 9587 | object[] outlist = new object[outlen]; |
8908 | // but that's shabby programming. | 9588 | for (i = 0; i < outlen; i ++) |
8909 | |||
8910 | if ((beginning == srclen) && (keepNulls)) | ||
8911 | { | 9589 | { |
8912 | if (srclen != 0) | 9590 | outlist[i] = new LSL_String(outarray[i]); |
8913 | tokens.Add(new LSL_String("")); | ||
8914 | } | 9591 | } |
8915 | 9592 | return new LSL_List(outlist); | |
8916 | return tokens; | ||
8917 | } | ||
8918 | |||
8919 | public LSL_List llParseString2List(string src, LSL_List separators, LSL_List spacers) | ||
8920 | { | ||
8921 | m_host.AddScriptLPS(1); | ||
8922 | return this.ParseString(src, separators, spacers, false); | ||
8923 | } | ||
8924 | |||
8925 | public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers) | ||
8926 | { | ||
8927 | m_host.AddScriptLPS(1); | ||
8928 | return this.ParseString(src, separators, spacers, true); | ||
8929 | } | 9593 | } |
8930 | 9594 | ||
8931 | public LSL_Integer llGetObjectPermMask(int mask) | 9595 | public LSL_Integer llGetObjectPermMask(int mask) |
@@ -9002,28 +9666,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9002 | { | 9666 | { |
9003 | m_host.AddScriptLPS(1); | 9667 | m_host.AddScriptLPS(1); |
9004 | 9668 | ||
9005 | lock (m_host.TaskInventory) | 9669 | m_host.TaskInventory.LockItemsForRead(true); |
9670 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | ||
9006 | { | 9671 | { |
9007 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | 9672 | if (inv.Value.Name == item) |
9008 | { | 9673 | { |
9009 | if (inv.Value.Name == item) | 9674 | m_host.TaskInventory.LockItemsForRead(false); |
9675 | switch (mask) | ||
9010 | { | 9676 | { |
9011 | switch (mask) | 9677 | case 0: |
9012 | { | 9678 | return (int)inv.Value.BasePermissions; |
9013 | case 0: | 9679 | case 1: |
9014 | return (int)inv.Value.BasePermissions; | 9680 | return (int)inv.Value.CurrentPermissions; |
9015 | case 1: | 9681 | case 2: |
9016 | return (int)inv.Value.CurrentPermissions; | 9682 | return (int)inv.Value.GroupPermissions; |
9017 | case 2: | 9683 | case 3: |
9018 | return (int)inv.Value.GroupPermissions; | 9684 | return (int)inv.Value.EveryonePermissions; |
9019 | case 3: | 9685 | case 4: |
9020 | return (int)inv.Value.EveryonePermissions; | 9686 | return (int)inv.Value.NextPermissions; |
9021 | case 4: | ||
9022 | return (int)inv.Value.NextPermissions; | ||
9023 | } | ||
9024 | } | 9687 | } |
9025 | } | 9688 | } |
9026 | } | 9689 | } |
9690 | m_host.TaskInventory.LockItemsForRead(false); | ||
9027 | 9691 | ||
9028 | return -1; | 9692 | return -1; |
9029 | } | 9693 | } |
@@ -9070,16 +9734,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9070 | { | 9734 | { |
9071 | m_host.AddScriptLPS(1); | 9735 | m_host.AddScriptLPS(1); |
9072 | 9736 | ||
9073 | lock (m_host.TaskInventory) | 9737 | m_host.TaskInventory.LockItemsForRead(true); |
9738 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | ||
9074 | { | 9739 | { |
9075 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | 9740 | if (inv.Value.Name == item) |
9076 | { | 9741 | { |
9077 | if (inv.Value.Name == item) | 9742 | m_host.TaskInventory.LockItemsForRead(false); |
9078 | { | 9743 | return inv.Value.CreatorID.ToString(); |
9079 | return inv.Value.CreatorID.ToString(); | ||
9080 | } | ||
9081 | } | 9744 | } |
9082 | } | 9745 | } |
9746 | m_host.TaskInventory.LockItemsForRead(false); | ||
9083 | 9747 | ||
9084 | llSay(0, "No item name '" + item + "'"); | 9748 | llSay(0, "No item name '" + item + "'"); |
9085 | 9749 | ||
@@ -9227,7 +9891,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9227 | } | 9891 | } |
9228 | 9892 | ||
9229 | /// <summary> | 9893 | /// <summary> |
9230 | /// illListReplaceList removes the sub-list defined by the inclusive indices | 9894 | /// llListReplaceList removes the sub-list defined by the inclusive indices |
9231 | /// start and end and inserts the src list in its place. The inclusive | 9895 | /// start and end and inserts the src list in its place. The inclusive |
9232 | /// nature of the indices means that at least one element must be deleted | 9896 | /// nature of the indices means that at least one element must be deleted |
9233 | /// if the indices are within the bounds of the existing list. I.e. 2,2 | 9897 | /// if the indices are within the bounds of the existing list. I.e. 2,2 |
@@ -9284,16 +9948,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9284 | // based upon end. Note that if end exceeds the upper | 9948 | // based upon end. Note that if end exceeds the upper |
9285 | // bound in this case, the entire destination list | 9949 | // bound in this case, the entire destination list |
9286 | // is removed. | 9950 | // is removed. |
9287 | else | 9951 | else if (start == 0) |
9288 | { | 9952 | { |
9289 | if (end + 1 < dest.Length) | 9953 | if (end + 1 < dest.Length) |
9290 | { | ||
9291 | return src + dest.GetSublist(end + 1, -1); | 9954 | return src + dest.GetSublist(end + 1, -1); |
9292 | } | ||
9293 | else | 9955 | else |
9294 | { | ||
9295 | return src; | 9956 | return src; |
9296 | } | 9957 | } |
9958 | else // Start < 0 | ||
9959 | { | ||
9960 | if (end + 1 < dest.Length) | ||
9961 | return dest.GetSublist(end + 1, -1); | ||
9962 | else | ||
9963 | return new LSL_List(); | ||
9297 | } | 9964 | } |
9298 | } | 9965 | } |
9299 | // Finally, if start > end, we strip away a prefix and | 9966 | // Finally, if start > end, we strip away a prefix and |
@@ -9344,17 +10011,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9344 | int width = 0; | 10011 | int width = 0; |
9345 | int height = 0; | 10012 | int height = 0; |
9346 | 10013 | ||
9347 | ParcelMediaCommandEnum? commandToSend = null; | 10014 | uint commandToSend = 0; |
9348 | float time = 0.0f; // default is from start | 10015 | float time = 0.0f; // default is from start |
9349 | 10016 | ||
9350 | ScenePresence presence = null; | 10017 | ScenePresence presence = null; |
9351 | 10018 | ||
9352 | for (int i = 0; i < commandList.Data.Length; i++) | 10019 | for (int i = 0; i < commandList.Data.Length; i++) |
9353 | { | 10020 | { |
9354 | ParcelMediaCommandEnum command = (ParcelMediaCommandEnum)commandList.Data[i]; | 10021 | uint command = (uint)(commandList.GetLSLIntegerItem(i)); |
9355 | switch (command) | 10022 | switch (command) |
9356 | { | 10023 | { |
9357 | case ParcelMediaCommandEnum.Agent: | 10024 | case (uint)ParcelMediaCommandEnum.Agent: |
9358 | // we send only to one agent | 10025 | // we send only to one agent |
9359 | if ((i + 1) < commandList.Length) | 10026 | if ((i + 1) < commandList.Length) |
9360 | { | 10027 | { |
@@ -9371,25 +10038,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9371 | } | 10038 | } |
9372 | break; | 10039 | break; |
9373 | 10040 | ||
9374 | case ParcelMediaCommandEnum.Loop: | 10041 | case (uint)ParcelMediaCommandEnum.Loop: |
9375 | loop = 1; | 10042 | loop = 1; |
9376 | commandToSend = command; | 10043 | commandToSend = command; |
9377 | update = true; //need to send the media update packet to set looping | 10044 | update = true; //need to send the media update packet to set looping |
9378 | break; | 10045 | break; |
9379 | 10046 | ||
9380 | case ParcelMediaCommandEnum.Play: | 10047 | case (uint)ParcelMediaCommandEnum.Play: |
9381 | loop = 0; | 10048 | loop = 0; |
9382 | commandToSend = command; | 10049 | commandToSend = command; |
9383 | update = true; //need to send the media update packet to make sure it doesn't loop | 10050 | update = true; //need to send the media update packet to make sure it doesn't loop |
9384 | break; | 10051 | break; |
9385 | 10052 | ||
9386 | case ParcelMediaCommandEnum.Pause: | 10053 | case (uint)ParcelMediaCommandEnum.Pause: |
9387 | case ParcelMediaCommandEnum.Stop: | 10054 | case (uint)ParcelMediaCommandEnum.Stop: |
9388 | case ParcelMediaCommandEnum.Unload: | 10055 | case (uint)ParcelMediaCommandEnum.Unload: |
9389 | commandToSend = command; | 10056 | commandToSend = command; |
9390 | break; | 10057 | break; |
9391 | 10058 | ||
9392 | case ParcelMediaCommandEnum.Url: | 10059 | case (uint)ParcelMediaCommandEnum.Url: |
9393 | if ((i + 1) < commandList.Length) | 10060 | if ((i + 1) < commandList.Length) |
9394 | { | 10061 | { |
9395 | if (commandList.Data[i + 1] is LSL_String) | 10062 | if (commandList.Data[i + 1] is LSL_String) |
@@ -9402,7 +10069,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9402 | } | 10069 | } |
9403 | break; | 10070 | break; |
9404 | 10071 | ||
9405 | case ParcelMediaCommandEnum.Texture: | 10072 | case (uint)ParcelMediaCommandEnum.Texture: |
9406 | if ((i + 1) < commandList.Length) | 10073 | if ((i + 1) < commandList.Length) |
9407 | { | 10074 | { |
9408 | if (commandList.Data[i + 1] is LSL_String) | 10075 | if (commandList.Data[i + 1] is LSL_String) |
@@ -9415,7 +10082,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9415 | } | 10082 | } |
9416 | break; | 10083 | break; |
9417 | 10084 | ||
9418 | case ParcelMediaCommandEnum.Time: | 10085 | case (uint)ParcelMediaCommandEnum.Time: |
9419 | if ((i + 1) < commandList.Length) | 10086 | if ((i + 1) < commandList.Length) |
9420 | { | 10087 | { |
9421 | if (commandList.Data[i + 1] is LSL_Float) | 10088 | if (commandList.Data[i + 1] is LSL_Float) |
@@ -9427,7 +10094,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9427 | } | 10094 | } |
9428 | break; | 10095 | break; |
9429 | 10096 | ||
9430 | case ParcelMediaCommandEnum.AutoAlign: | 10097 | case (uint)ParcelMediaCommandEnum.AutoAlign: |
9431 | if ((i + 1) < commandList.Length) | 10098 | if ((i + 1) < commandList.Length) |
9432 | { | 10099 | { |
9433 | if (commandList.Data[i + 1] is LSL_Integer) | 10100 | if (commandList.Data[i + 1] is LSL_Integer) |
@@ -9441,7 +10108,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9441 | } | 10108 | } |
9442 | break; | 10109 | break; |
9443 | 10110 | ||
9444 | case ParcelMediaCommandEnum.Type: | 10111 | case (uint)ParcelMediaCommandEnum.Type: |
9445 | if ((i + 1) < commandList.Length) | 10112 | if ((i + 1) < commandList.Length) |
9446 | { | 10113 | { |
9447 | if (commandList.Data[i + 1] is LSL_String) | 10114 | if (commandList.Data[i + 1] is LSL_String) |
@@ -9454,7 +10121,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9454 | } | 10121 | } |
9455 | break; | 10122 | break; |
9456 | 10123 | ||
9457 | case ParcelMediaCommandEnum.Desc: | 10124 | case (uint)ParcelMediaCommandEnum.Desc: |
9458 | if ((i + 1) < commandList.Length) | 10125 | if ((i + 1) < commandList.Length) |
9459 | { | 10126 | { |
9460 | if (commandList.Data[i + 1] is LSL_String) | 10127 | if (commandList.Data[i + 1] is LSL_String) |
@@ -9467,7 +10134,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9467 | } | 10134 | } |
9468 | break; | 10135 | break; |
9469 | 10136 | ||
9470 | case ParcelMediaCommandEnum.Size: | 10137 | case (uint)ParcelMediaCommandEnum.Size: |
9471 | if ((i + 2) < commandList.Length) | 10138 | if ((i + 2) < commandList.Length) |
9472 | { | 10139 | { |
9473 | if (commandList.Data[i + 1] is LSL_Integer) | 10140 | if (commandList.Data[i + 1] is LSL_Integer) |
@@ -9537,7 +10204,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9537 | } | 10204 | } |
9538 | } | 10205 | } |
9539 | 10206 | ||
9540 | if (commandToSend != null) | 10207 | if (commandToSend != 0) |
9541 | { | 10208 | { |
9542 | // the commandList contained a start/stop/... command, too | 10209 | // the commandList contained a start/stop/... command, too |
9543 | if (presence == null) | 10210 | if (presence == null) |
@@ -9574,7 +10241,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9574 | 10241 | ||
9575 | if (aList.Data[i] != null) | 10242 | if (aList.Data[i] != null) |
9576 | { | 10243 | { |
9577 | switch ((ParcelMediaCommandEnum) aList.Data[i]) | 10244 | switch ((ParcelMediaCommandEnum) Convert.ToInt32(aList.Data[i].ToString())) |
9578 | { | 10245 | { |
9579 | case ParcelMediaCommandEnum.Url: | 10246 | case ParcelMediaCommandEnum.Url: |
9580 | list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaURL)); | 10247 | list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaURL)); |
@@ -9617,16 +10284,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9617 | { | 10284 | { |
9618 | m_host.AddScriptLPS(1); | 10285 | m_host.AddScriptLPS(1); |
9619 | 10286 | ||
9620 | lock (m_host.TaskInventory) | 10287 | m_host.TaskInventory.LockItemsForRead(true); |
10288 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | ||
9621 | { | 10289 | { |
9622 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | 10290 | if (inv.Value.Name == name) |
9623 | { | 10291 | { |
9624 | if (inv.Value.Name == name) | 10292 | m_host.TaskInventory.LockItemsForRead(false); |
9625 | { | 10293 | return inv.Value.Type; |
9626 | return inv.Value.Type; | ||
9627 | } | ||
9628 | } | 10294 | } |
9629 | } | 10295 | } |
10296 | m_host.TaskInventory.LockItemsForRead(false); | ||
9630 | 10297 | ||
9631 | return -1; | 10298 | return -1; |
9632 | } | 10299 | } |
@@ -9637,15 +10304,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9637 | 10304 | ||
9638 | if (quick_pay_buttons.Data.Length < 4) | 10305 | if (quick_pay_buttons.Data.Length < 4) |
9639 | { | 10306 | { |
9640 | LSLError("List must have at least 4 elements"); | 10307 | int x; |
9641 | return; | 10308 | for (x=quick_pay_buttons.Data.Length; x<= 4; x++) |
10309 | { | ||
10310 | quick_pay_buttons.Add(ScriptBaseClass.PAY_HIDE); | ||
10311 | } | ||
9642 | } | 10312 | } |
9643 | m_host.ParentGroup.RootPart.PayPrice[0]=price; | 10313 | int[] nPrice = new int[5]; |
9644 | 10314 | nPrice[0] = price; | |
9645 | m_host.ParentGroup.RootPart.PayPrice[1]=(LSL_Integer)quick_pay_buttons.Data[0]; | 10315 | nPrice[1] = quick_pay_buttons.GetLSLIntegerItem(0); |
9646 | m_host.ParentGroup.RootPart.PayPrice[2]=(LSL_Integer)quick_pay_buttons.Data[1]; | 10316 | nPrice[2] = quick_pay_buttons.GetLSLIntegerItem(1); |
9647 | m_host.ParentGroup.RootPart.PayPrice[3]=(LSL_Integer)quick_pay_buttons.Data[2]; | 10317 | nPrice[3] = quick_pay_buttons.GetLSLIntegerItem(2); |
9648 | m_host.ParentGroup.RootPart.PayPrice[4]=(LSL_Integer)quick_pay_buttons.Data[3]; | 10318 | nPrice[4] = quick_pay_buttons.GetLSLIntegerItem(3); |
10319 | m_host.ParentGroup.RootPart.PayPrice = nPrice; | ||
9649 | m_host.ParentGroup.HasGroupChanged = true; | 10320 | m_host.ParentGroup.HasGroupChanged = true; |
9650 | } | 10321 | } |
9651 | 10322 | ||
@@ -9657,17 +10328,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9657 | if (invItemID == UUID.Zero) | 10328 | if (invItemID == UUID.Zero) |
9658 | return new LSL_Vector(); | 10329 | return new LSL_Vector(); |
9659 | 10330 | ||
9660 | lock (m_host.TaskInventory) | 10331 | m_host.TaskInventory.LockItemsForRead(true); |
10332 | if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) | ||
9661 | { | 10333 | { |
9662 | if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) | 10334 | m_host.TaskInventory.LockItemsForRead(false); |
9663 | return new LSL_Vector(); | 10335 | return new LSL_Vector(); |
10336 | } | ||
9664 | 10337 | ||
9665 | if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) | 10338 | if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) |
9666 | { | 10339 | { |
9667 | ShoutError("No permissions to track the camera"); | 10340 | ShoutError("No permissions to track the camera"); |
9668 | return new LSL_Vector(); | 10341 | m_host.TaskInventory.LockItemsForRead(false); |
9669 | } | 10342 | return new LSL_Vector(); |
9670 | } | 10343 | } |
10344 | m_host.TaskInventory.LockItemsForRead(false); | ||
9671 | 10345 | ||
9672 | ScenePresence presence = World.GetScenePresence(m_host.OwnerID); | 10346 | ScenePresence presence = World.GetScenePresence(m_host.OwnerID); |
9673 | if (presence != null) | 10347 | if (presence != null) |
@@ -9685,17 +10359,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9685 | if (invItemID == UUID.Zero) | 10359 | if (invItemID == UUID.Zero) |
9686 | return new LSL_Rotation(); | 10360 | return new LSL_Rotation(); |
9687 | 10361 | ||
9688 | lock (m_host.TaskInventory) | 10362 | m_host.TaskInventory.LockItemsForRead(true); |
10363 | if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) | ||
9689 | { | 10364 | { |
9690 | if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) | 10365 | m_host.TaskInventory.LockItemsForRead(false); |
9691 | return new LSL_Rotation(); | 10366 | return new LSL_Rotation(); |
9692 | 10367 | } | |
9693 | if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) | 10368 | if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) |
9694 | { | 10369 | { |
9695 | ShoutError("No permissions to track the camera"); | 10370 | ShoutError("No permissions to track the camera"); |
9696 | return new LSL_Rotation(); | 10371 | m_host.TaskInventory.LockItemsForRead(false); |
9697 | } | 10372 | return new LSL_Rotation(); |
9698 | } | 10373 | } |
10374 | m_host.TaskInventory.LockItemsForRead(false); | ||
9699 | 10375 | ||
9700 | ScenePresence presence = World.GetScenePresence(m_host.OwnerID); | 10376 | ScenePresence presence = World.GetScenePresence(m_host.OwnerID); |
9701 | if (presence != null) | 10377 | if (presence != null) |
@@ -9757,8 +10433,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9757 | { | 10433 | { |
9758 | m_host.AddScriptLPS(1); | 10434 | m_host.AddScriptLPS(1); |
9759 | DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0); | 10435 | DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0); |
9760 | if (detectedParams == null) return; // only works on the first detected avatar | 10436 | if (detectedParams == null) |
9761 | 10437 | { | |
10438 | if (m_host.ParentGroup.IsAttachment == true) | ||
10439 | { | ||
10440 | detectedParams = new DetectParams(); | ||
10441 | detectedParams.Key = m_host.OwnerID; | ||
10442 | } | ||
10443 | else | ||
10444 | { | ||
10445 | return; | ||
10446 | } | ||
10447 | } | ||
10448 | |||
9762 | ScenePresence avatar = World.GetScenePresence(detectedParams.Key); | 10449 | ScenePresence avatar = World.GetScenePresence(detectedParams.Key); |
9763 | if (avatar != null) | 10450 | if (avatar != null) |
9764 | { | 10451 | { |
@@ -9766,6 +10453,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9766 | new Vector3((float)pos.x, (float)pos.y, (float)pos.z), | 10453 | new Vector3((float)pos.x, (float)pos.y, (float)pos.z), |
9767 | new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z)); | 10454 | new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z)); |
9768 | } | 10455 | } |
10456 | |||
9769 | ScriptSleep(1000); | 10457 | ScriptSleep(1000); |
9770 | } | 10458 | } |
9771 | 10459 | ||
@@ -9877,14 +10565,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9877 | if (objectID == UUID.Zero) return; | 10565 | if (objectID == UUID.Zero) return; |
9878 | 10566 | ||
9879 | UUID agentID; | 10567 | UUID agentID; |
9880 | lock (m_host.TaskInventory) | 10568 | m_host.TaskInventory.LockItemsForRead(true); |
9881 | { | 10569 | // we need the permission first, to know which avatar we want to set the camera for |
9882 | // we need the permission first, to know which avatar we want to set the camera for | 10570 | agentID = m_host.TaskInventory[invItemID].PermsGranter; |
9883 | agentID = m_host.TaskInventory[invItemID].PermsGranter; | ||
9884 | 10571 | ||
9885 | if (agentID == UUID.Zero) return; | 10572 | if (agentID == UUID.Zero) |
9886 | if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return; | 10573 | { |
10574 | m_host.TaskInventory.LockItemsForRead(false); | ||
10575 | return; | ||
10576 | } | ||
10577 | if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) | ||
10578 | { | ||
10579 | m_host.TaskInventory.LockItemsForRead(false); | ||
10580 | return; | ||
9887 | } | 10581 | } |
10582 | m_host.TaskInventory.LockItemsForRead(false); | ||
9888 | 10583 | ||
9889 | ScenePresence presence = World.GetScenePresence(agentID); | 10584 | ScenePresence presence = World.GetScenePresence(agentID); |
9890 | 10585 | ||
@@ -9893,12 +10588,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9893 | 10588 | ||
9894 | SortedDictionary<int, float> parameters = new SortedDictionary<int, float>(); | 10589 | SortedDictionary<int, float> parameters = new SortedDictionary<int, float>(); |
9895 | object[] data = rules.Data; | 10590 | object[] data = rules.Data; |
9896 | for (int i = 0; i < data.Length; ++i) { | 10591 | for (int i = 0; i < data.Length; ++i) |
10592 | { | ||
9897 | int type = Convert.ToInt32(data[i++].ToString()); | 10593 | int type = Convert.ToInt32(data[i++].ToString()); |
9898 | if (i >= data.Length) break; // odd number of entries => ignore the last | 10594 | if (i >= data.Length) break; // odd number of entries => ignore the last |
9899 | 10595 | ||
9900 | // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3) | 10596 | // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3) |
9901 | switch (type) { | 10597 | switch (type) |
10598 | { | ||
9902 | case ScriptBaseClass.CAMERA_FOCUS: | 10599 | case ScriptBaseClass.CAMERA_FOCUS: |
9903 | case ScriptBaseClass.CAMERA_FOCUS_OFFSET: | 10600 | case ScriptBaseClass.CAMERA_FOCUS_OFFSET: |
9904 | case ScriptBaseClass.CAMERA_POSITION: | 10601 | case ScriptBaseClass.CAMERA_POSITION: |
@@ -9934,12 +10631,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9934 | 10631 | ||
9935 | // we need the permission first, to know which avatar we want to clear the camera for | 10632 | // we need the permission first, to know which avatar we want to clear the camera for |
9936 | UUID agentID; | 10633 | UUID agentID; |
9937 | lock (m_host.TaskInventory) | 10634 | m_host.TaskInventory.LockItemsForRead(true); |
10635 | agentID = m_host.TaskInventory[invItemID].PermsGranter; | ||
10636 | if (agentID == UUID.Zero) | ||
10637 | { | ||
10638 | m_host.TaskInventory.LockItemsForRead(false); | ||
10639 | return; | ||
10640 | } | ||
10641 | if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) | ||
9938 | { | 10642 | { |
9939 | agentID = m_host.TaskInventory[invItemID].PermsGranter; | 10643 | m_host.TaskInventory.LockItemsForRead(false); |
9940 | if (agentID == UUID.Zero) return; | 10644 | return; |
9941 | if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return; | ||
9942 | } | 10645 | } |
10646 | m_host.TaskInventory.LockItemsForRead(false); | ||
9943 | 10647 | ||
9944 | ScenePresence presence = World.GetScenePresence(agentID); | 10648 | ScenePresence presence = World.GetScenePresence(agentID); |
9945 | 10649 | ||
@@ -10006,19 +10710,65 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10006 | public LSL_String llXorBase64StringsCorrect(string str1, string str2) | 10710 | public LSL_String llXorBase64StringsCorrect(string str1, string str2) |
10007 | { | 10711 | { |
10008 | m_host.AddScriptLPS(1); | 10712 | m_host.AddScriptLPS(1); |
10009 | string ret = String.Empty; | 10713 | |
10010 | string src1 = llBase64ToString(str1); | 10714 | if (str1 == String.Empty) |
10011 | string src2 = llBase64ToString(str2); | 10715 | return String.Empty; |
10012 | int c = 0; | 10716 | if (str2 == String.Empty) |
10013 | for (int i = 0; i < src1.Length; i++) | 10717 | return str1; |
10718 | |||
10719 | int len = str2.Length; | ||
10720 | if ((len % 4) != 0) // LL is EVIL!!!! | ||
10721 | { | ||
10722 | while (str2.EndsWith("=")) | ||
10723 | str2 = str2.Substring(0, str2.Length - 1); | ||
10724 | |||
10725 | len = str2.Length; | ||
10726 | int mod = len % 4; | ||
10727 | |||
10728 | if (mod == 1) | ||
10729 | str2 = str2.Substring(0, str2.Length - 1); | ||
10730 | else if (mod == 2) | ||
10731 | str2 += "=="; | ||
10732 | else if (mod == 3) | ||
10733 | str2 += "="; | ||
10734 | } | ||
10735 | |||
10736 | byte[] data1; | ||
10737 | byte[] data2; | ||
10738 | try | ||
10739 | { | ||
10740 | data1 = Convert.FromBase64String(str1); | ||
10741 | data2 = Convert.FromBase64String(str2); | ||
10742 | } | ||
10743 | catch (Exception) | ||
10014 | { | 10744 | { |
10015 | ret += (char) (src1[i] ^ src2[c]); | 10745 | return new LSL_String(String.Empty); |
10746 | } | ||
10747 | |||
10748 | byte[] d2 = new Byte[data1.Length]; | ||
10749 | int pos = 0; | ||
10750 | |||
10751 | if (data1.Length <= data2.Length) | ||
10752 | { | ||
10753 | Array.Copy(data2, 0, d2, 0, data1.Length); | ||
10754 | } | ||
10755 | else | ||
10756 | { | ||
10757 | while (pos < data1.Length) | ||
10758 | { | ||
10759 | len = data1.Length - pos; | ||
10760 | if (len > data2.Length) | ||
10761 | len = data2.Length; | ||
10016 | 10762 | ||
10017 | c++; | 10763 | Array.Copy(data2, 0, d2, pos, len); |
10018 | if (c >= src2.Length) | 10764 | pos += len; |
10019 | c = 0; | 10765 | } |
10020 | } | 10766 | } |
10021 | return llStringToBase64(ret); | 10767 | |
10768 | for (pos = 0 ; pos < data1.Length ; pos++ ) | ||
10769 | data1[pos] ^= d2[pos]; | ||
10770 | |||
10771 | return Convert.ToBase64String(data1); | ||
10022 | } | 10772 | } |
10023 | 10773 | ||
10024 | public LSL_String llHTTPRequest(string url, LSL_List parameters, string body) | 10774 | public LSL_String llHTTPRequest(string url, LSL_List parameters, string body) |
@@ -10075,12 +10825,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10075 | Regex r = new Regex(authregex); | 10825 | Regex r = new Regex(authregex); |
10076 | int[] gnums = r.GetGroupNumbers(); | 10826 | int[] gnums = r.GetGroupNumbers(); |
10077 | Match m = r.Match(url); | 10827 | Match m = r.Match(url); |
10078 | if (m.Success) { | 10828 | if (m.Success) |
10079 | for (int i = 1; i < gnums.Length; i++) { | 10829 | { |
10830 | for (int i = 1; i < gnums.Length; i++) | ||
10831 | { | ||
10080 | //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]]; | 10832 | //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]]; |
10081 | //CaptureCollection cc = g.Captures; | 10833 | //CaptureCollection cc = g.Captures; |
10082 | } | 10834 | } |
10083 | if (m.Groups.Count == 5) { | 10835 | if (m.Groups.Count == 5) |
10836 | { | ||
10084 | httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString()))); | 10837 | httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString()))); |
10085 | url = m.Groups[1].ToString() + m.Groups[4].ToString(); | 10838 | url = m.Groups[1].ToString() + m.Groups[4].ToString(); |
10086 | } | 10839 | } |
@@ -10366,15 +11119,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10366 | 11119 | ||
10367 | internal UUID ScriptByName(string name) | 11120 | internal UUID ScriptByName(string name) |
10368 | { | 11121 | { |
10369 | lock (m_host.TaskInventory) | 11122 | m_host.TaskInventory.LockItemsForRead(true); |
11123 | |||
11124 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | ||
10370 | { | 11125 | { |
10371 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | 11126 | if (item.Type == 10 && item.Name == name) |
10372 | { | 11127 | { |
10373 | if (item.Type == 10 && item.Name == name) | 11128 | m_host.TaskInventory.LockItemsForRead(false); |
10374 | return item.ItemID; | 11129 | return item.ItemID; |
10375 | } | 11130 | } |
10376 | } | 11131 | } |
10377 | 11132 | ||
11133 | m_host.TaskInventory.LockItemsForRead(false); | ||
11134 | |||
10378 | return UUID.Zero; | 11135 | return UUID.Zero; |
10379 | } | 11136 | } |
10380 | 11137 | ||
@@ -10415,6 +11172,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10415 | { | 11172 | { |
10416 | m_host.AddScriptLPS(1); | 11173 | m_host.AddScriptLPS(1); |
10417 | 11174 | ||
11175 | //Clone is thread safe | ||
10418 | TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); | 11176 | TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); |
10419 | 11177 | ||
10420 | UUID assetID = UUID.Zero; | 11178 | UUID assetID = UUID.Zero; |
@@ -10477,6 +11235,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10477 | { | 11235 | { |
10478 | m_host.AddScriptLPS(1); | 11236 | m_host.AddScriptLPS(1); |
10479 | 11237 | ||
11238 | //Clone is thread safe | ||
10480 | TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); | 11239 | TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); |
10481 | 11240 | ||
10482 | UUID assetID = UUID.Zero; | 11241 | UUID assetID = UUID.Zero; |
@@ -10557,15 +11316,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10557 | return GetLinkPrimitiveParams(obj, rules); | 11316 | return GetLinkPrimitiveParams(obj, rules); |
10558 | } | 11317 | } |
10559 | 11318 | ||
10560 | public void print(string str) | 11319 | public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link) |
10561 | { | 11320 | { |
10562 | // yes, this is a real LSL function. See: http://wiki.secondlife.com/wiki/Print | 11321 | List<SceneObjectPart> parts = GetLinkParts(link); |
10563 | IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_itemID, "OSSL"); | 11322 | if (parts.Count < 1) |
10564 | if (ossl != null) | 11323 | return 0; |
10565 | { | 11324 | |
10566 | ossl.CheckThreatLevel(ThreatLevel.High, "print"); | 11325 | return GetNumberOfSides(parts[0]); |
10567 | m_log.Info("LSL print():" + str); | ||
10568 | } | ||
10569 | } | 11326 | } |
10570 | 11327 | ||
10571 | private string Name2Username(string name) | 11328 | private string Name2Username(string name) |
@@ -10611,153 +11368,397 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10611 | return rq.ToString(); | 11368 | return rq.ToString(); |
10612 | } | 11369 | } |
10613 | 11370 | ||
11371 | private void SayShoutTimerElapsed(Object sender, ElapsedEventArgs args) | ||
11372 | { | ||
11373 | m_SayShoutCount = 0; | ||
11374 | } | ||
11375 | |||
11376 | private struct Tri | ||
11377 | { | ||
11378 | public Vector3 p1; | ||
11379 | public Vector3 p2; | ||
11380 | public Vector3 p3; | ||
11381 | } | ||
11382 | |||
11383 | private bool InBoundingBox(ScenePresence avatar, Vector3 point) | ||
11384 | { | ||
11385 | float height = avatar.Appearance.AvatarHeight; | ||
11386 | Vector3 b1 = avatar.AbsolutePosition + new Vector3(-0.22f, -0.22f, -height/2); | ||
11387 | Vector3 b2 = avatar.AbsolutePosition + new Vector3(0.22f, 0.22f, height/2); | ||
11388 | |||
11389 | if (point.X > b1.X && point.X < b2.X && | ||
11390 | point.Y > b1.Y && point.Y < b2.Y && | ||
11391 | point.Z > b1.Z && point.Z < b2.Z) | ||
11392 | return true; | ||
11393 | return false; | ||
11394 | } | ||
11395 | |||
11396 | private ContactResult[] AvatarIntersection(Vector3 rayStart, Vector3 rayEnd) | ||
11397 | { | ||
11398 | List<ContactResult> contacts = new List<ContactResult>(); | ||
11399 | |||
11400 | Vector3 ab = rayEnd - rayStart; | ||
11401 | |||
11402 | World.ForEachScenePresence(delegate(ScenePresence sp) | ||
11403 | { | ||
11404 | Vector3 ac = sp.AbsolutePosition - rayStart; | ||
11405 | Vector3 bc = sp.AbsolutePosition - rayEnd; | ||
11406 | |||
11407 | double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / Vector3.Distance(rayStart, rayEnd)); | ||
11408 | |||
11409 | if (d > 1.5) | ||
11410 | return; | ||
11411 | |||
11412 | double d2 = Vector3.Dot(Vector3.Negate(ab), ac); | ||
11413 | |||
11414 | if (d2 > 0) | ||
11415 | return; | ||
11416 | |||
11417 | double dp = Math.Sqrt(Vector3.Mag(ac) * Vector3.Mag(ac) - d * d); | ||
11418 | Vector3 p = rayStart + Vector3.Divide(Vector3.Multiply(ab, (float)dp), (float)Vector3.Mag(ab)); | ||
11419 | |||
11420 | if (!InBoundingBox(sp, p)) | ||
11421 | return; | ||
11422 | |||
11423 | ContactResult result = new ContactResult (); | ||
11424 | result.ConsumerID = sp.LocalId; | ||
11425 | result.Depth = Vector3.Distance(rayStart, p); | ||
11426 | result.Normal = Vector3.Zero; | ||
11427 | result.Pos = p; | ||
11428 | |||
11429 | contacts.Add(result); | ||
11430 | }); | ||
11431 | |||
11432 | return contacts.ToArray(); | ||
11433 | } | ||
11434 | |||
11435 | private ContactResult[] ObjectIntersection(Vector3 rayStart, Vector3 rayEnd, bool includePhysical, bool includeNonPhysical, bool includePhantom) | ||
11436 | { | ||
11437 | Ray ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart)); | ||
11438 | List<ContactResult> contacts = new List<ContactResult>(); | ||
11439 | |||
11440 | Vector3 ab = rayEnd - rayStart; | ||
11441 | |||
11442 | World.ForEachSOG(delegate(SceneObjectGroup group) | ||
11443 | { | ||
11444 | if (m_host.ParentGroup == group) | ||
11445 | return; | ||
11446 | |||
11447 | if (group.IsAttachment) | ||
11448 | return; | ||
11449 | |||
11450 | if (group.RootPart.PhysActor == null) | ||
11451 | { | ||
11452 | if (!includePhantom) | ||
11453 | return; | ||
11454 | } | ||
11455 | else | ||
11456 | { | ||
11457 | if (group.RootPart.PhysActor.IsPhysical) | ||
11458 | { | ||
11459 | if (!includePhysical) | ||
11460 | return; | ||
11461 | } | ||
11462 | else | ||
11463 | { | ||
11464 | if (!includeNonPhysical) | ||
11465 | return; | ||
11466 | } | ||
11467 | } | ||
11468 | |||
11469 | // Find the radius ouside of which we don't even need to hit test | ||
11470 | float minX; | ||
11471 | float maxX; | ||
11472 | float minY; | ||
11473 | float maxY; | ||
11474 | float minZ; | ||
11475 | float maxZ; | ||
11476 | |||
11477 | float radius = 0.0f; | ||
11478 | |||
11479 | group.GetAxisAlignedBoundingBoxRaw(out minX, out maxX, out minY, out maxY, out minZ, out maxZ); | ||
11480 | |||
11481 | if (Math.Abs(minX) > radius) | ||
11482 | radius = Math.Abs(minX); | ||
11483 | if (Math.Abs(minY) > radius) | ||
11484 | radius = Math.Abs(minY); | ||
11485 | if (Math.Abs(minZ) > radius) | ||
11486 | radius = Math.Abs(minZ); | ||
11487 | if (Math.Abs(maxX) > radius) | ||
11488 | radius = Math.Abs(maxX); | ||
11489 | if (Math.Abs(maxY) > radius) | ||
11490 | radius = Math.Abs(maxY); | ||
11491 | if (Math.Abs(maxZ) > radius) | ||
11492 | radius = Math.Abs(maxZ); | ||
11493 | |||
11494 | Vector3 ac = group.AbsolutePosition - rayStart; | ||
11495 | Vector3 bc = group.AbsolutePosition - rayEnd; | ||
11496 | |||
11497 | double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / Vector3.Distance(rayStart, rayEnd)); | ||
11498 | |||
11499 | // Too far off ray, don't bother | ||
11500 | if (d > radius) | ||
11501 | return; | ||
11502 | |||
11503 | // Behind ray, drop | ||
11504 | double d2 = Vector3.Dot(Vector3.Negate(ab), ac); | ||
11505 | if (d2 > 0) | ||
11506 | return; | ||
11507 | |||
11508 | EntityIntersection intersection = group.TestIntersection(ray, true, false); | ||
11509 | // Miss. | ||
11510 | if (!intersection.HitTF) | ||
11511 | return; | ||
11512 | |||
11513 | ContactResult result = new ContactResult (); | ||
11514 | result.ConsumerID = group.LocalId; | ||
11515 | result.Depth = intersection.distance; | ||
11516 | result.Normal = intersection.normal; | ||
11517 | result.Pos = intersection.ipoint; | ||
11518 | |||
11519 | contacts.Add(result); | ||
11520 | }); | ||
11521 | |||
11522 | return contacts.ToArray(); | ||
11523 | } | ||
11524 | |||
11525 | private ContactResult? GroundIntersection(Vector3 rayStart, Vector3 rayEnd) | ||
11526 | { | ||
11527 | double[,] heightfield = World.Heightmap.GetDoubles(); | ||
11528 | List<ContactResult> contacts = new List<ContactResult>(); | ||
11529 | |||
11530 | double min = 2048.0; | ||
11531 | double max = 0.0; | ||
11532 | |||
11533 | // Find the min and max of the heightfield | ||
11534 | for (int x = 0 ; x < World.Heightmap.Width ; x++) | ||
11535 | { | ||
11536 | for (int y = 0 ; y < World.Heightmap.Height ; y++) | ||
11537 | { | ||
11538 | if (heightfield[x, y] > max) | ||
11539 | max = heightfield[x, y]; | ||
11540 | if (heightfield[x, y] < min) | ||
11541 | min = heightfield[x, y]; | ||
11542 | } | ||
11543 | } | ||
11544 | |||
11545 | |||
11546 | // A ray extends past rayEnd, but doesn't go back before | ||
11547 | // rayStart. If the start is above the highest point of the ground | ||
11548 | // and the ray goes up, we can't hit the ground. Ever. | ||
11549 | if (rayStart.Z > max && rayEnd.Z >= rayStart.Z) | ||
11550 | return null; | ||
11551 | |||
11552 | // Same for going down | ||
11553 | if (rayStart.Z < min && rayEnd.Z <= rayStart.Z) | ||
11554 | return null; | ||
11555 | |||
11556 | List<Tri> trilist = new List<Tri>(); | ||
11557 | |||
11558 | // Create our triangle list | ||
11559 | for (int x = 1 ; x < World.Heightmap.Width ; x++) | ||
11560 | { | ||
11561 | for (int y = 1 ; y < World.Heightmap.Height ; y++) | ||
11562 | { | ||
11563 | Tri t1 = new Tri(); | ||
11564 | Tri t2 = new Tri(); | ||
11565 | |||
11566 | Vector3 p1 = new Vector3(x-1, y-1, (float)heightfield[x-1, y-1]); | ||
11567 | Vector3 p2 = new Vector3(x, y-1, (float)heightfield[x, y-1]); | ||
11568 | Vector3 p3 = new Vector3(x, y, (float)heightfield[x, y]); | ||
11569 | Vector3 p4 = new Vector3(x-1, y, (float)heightfield[x-1, y]); | ||
11570 | |||
11571 | t1.p1 = p1; | ||
11572 | t1.p2 = p2; | ||
11573 | t1.p3 = p3; | ||
11574 | |||
11575 | t2.p1 = p3; | ||
11576 | t2.p2 = p4; | ||
11577 | t2.p3 = p1; | ||
11578 | |||
11579 | trilist.Add(t1); | ||
11580 | trilist.Add(t2); | ||
11581 | } | ||
11582 | } | ||
11583 | |||
11584 | // Ray direction | ||
11585 | Vector3 rayDirection = rayEnd - rayStart; | ||
11586 | |||
11587 | foreach (Tri t in trilist) | ||
11588 | { | ||
11589 | // Compute triangle plane normal and edges | ||
11590 | Vector3 u = t.p2 - t.p1; | ||
11591 | Vector3 v = t.p3 - t.p1; | ||
11592 | Vector3 n = Vector3.Cross(u, v); | ||
11593 | |||
11594 | if (n == Vector3.Zero) | ||
11595 | continue; | ||
11596 | |||
11597 | Vector3 w0 = rayStart - t.p1; | ||
11598 | double a = -Vector3.Dot(n, w0); | ||
11599 | double b = Vector3.Dot(n, rayDirection); | ||
11600 | |||
11601 | // Not intersecting the plane, or in plane (same thing) | ||
11602 | // Ignoring this MAY cause the ground to not be detected | ||
11603 | // sometimes | ||
11604 | if (Math.Abs(b) < 0.000001) | ||
11605 | continue; | ||
11606 | |||
11607 | double r = a / b; | ||
11608 | |||
11609 | // ray points away from plane | ||
11610 | if (r < 0.0) | ||
11611 | continue; | ||
11612 | |||
11613 | Vector3 ip = rayStart + Vector3.Multiply(rayDirection, (float)r); | ||
11614 | |||
11615 | float uu = Vector3.Dot(u, u); | ||
11616 | float uv = Vector3.Dot(u, v); | ||
11617 | float vv = Vector3.Dot(v, v); | ||
11618 | Vector3 w = ip - t.p1; | ||
11619 | float wu = Vector3.Dot(w, u); | ||
11620 | float wv = Vector3.Dot(w, v); | ||
11621 | float d = uv * uv - uu * vv; | ||
11622 | |||
11623 | float cs = (uv * wv - vv * wu) / d; | ||
11624 | if (cs < 0 || cs > 1.0) | ||
11625 | continue; | ||
11626 | float ct = (uv * wu - uu * wv) / d; | ||
11627 | if (ct < 0 || (cs + ct) > 1.0) | ||
11628 | continue; | ||
11629 | |||
11630 | // Add contact point | ||
11631 | ContactResult result = new ContactResult (); | ||
11632 | result.ConsumerID = 0; | ||
11633 | result.Depth = Vector3.Distance(rayStart, ip); | ||
11634 | result.Normal = n; | ||
11635 | result.Pos = ip; | ||
11636 | |||
11637 | contacts.Add(result); | ||
11638 | } | ||
11639 | |||
11640 | if (contacts.Count == 0) | ||
11641 | return null; | ||
11642 | |||
11643 | contacts.Sort(delegate(ContactResult a, ContactResult b) | ||
11644 | { | ||
11645 | return (int)(a.Depth - b.Depth); | ||
11646 | }); | ||
11647 | |||
11648 | return contacts[0]; | ||
11649 | } | ||
11650 | |||
10614 | public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options) | 11651 | public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options) |
10615 | { | 11652 | { |
11653 | LSL_List list = new LSL_List(); | ||
11654 | |||
10616 | m_host.AddScriptLPS(1); | 11655 | m_host.AddScriptLPS(1); |
10617 | 11656 | ||
10618 | Vector3 dir = new Vector3((float)(end-start).x, (float)(end-start).y, (float)(end-start).z); | 11657 | Vector3 rayStart = new Vector3((float)start.x, (float)start.y, (float)start.z); |
10619 | Vector3 startvector = new Vector3((float)start.x, (float)start.y, (float)start.z); | 11658 | Vector3 rayEnd = new Vector3((float)end.x, (float)end.y, (float)end.z); |
10620 | Vector3 endvector = new Vector3((float)end.x, (float)end.y, (float)end.z); | 11659 | Vector3 dir = rayEnd - rayStart; |
10621 | 11660 | ||
10622 | int count = 0; | 11661 | float dist = Vector3.Mag(dir); |
10623 | // int detectPhantom = 0; | 11662 | |
11663 | int count = 1; | ||
11664 | bool detectPhantom = false; | ||
10624 | int dataFlags = 0; | 11665 | int dataFlags = 0; |
10625 | int rejectTypes = 0; | 11666 | int rejectTypes = 0; |
10626 | 11667 | ||
10627 | for (int i = 0; i < options.Length; i += 2) | 11668 | for (int i = 0; i < options.Length; i += 2) |
10628 | { | 11669 | { |
10629 | if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS) | 11670 | if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS) |
10630 | { | ||
10631 | count = options.GetLSLIntegerItem(i + 1); | 11671 | count = options.GetLSLIntegerItem(i + 1); |
10632 | } | 11672 | else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM) |
10633 | // else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM) | 11673 | detectPhantom = (options.GetLSLIntegerItem(i + 1) > 0); |
10634 | // { | ||
10635 | // detectPhantom = options.GetLSLIntegerItem(i + 1); | ||
10636 | // } | ||
10637 | else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS) | 11674 | else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS) |
10638 | { | ||
10639 | dataFlags = options.GetLSLIntegerItem(i + 1); | 11675 | dataFlags = options.GetLSLIntegerItem(i + 1); |
10640 | } | ||
10641 | else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES) | 11676 | else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES) |
10642 | { | ||
10643 | rejectTypes = options.GetLSLIntegerItem(i + 1); | 11677 | rejectTypes = options.GetLSLIntegerItem(i + 1); |
10644 | } | ||
10645 | } | 11678 | } |
10646 | 11679 | ||
10647 | LSL_List list = new LSL_List(); | 11680 | if (count > 16) |
10648 | List<ContactResult> results = World.PhysicsScene.RaycastWorld(startvector, dir, dir.Length(), count); | 11681 | count = 16; |
10649 | 11682 | ||
10650 | double distance = Util.GetDistanceTo(startvector, endvector); | 11683 | List<ContactResult> results = new List<ContactResult>(); |
10651 | |||
10652 | if (distance == 0) | ||
10653 | distance = 0.001; | ||
10654 | |||
10655 | Vector3 posToCheck = startvector; | ||
10656 | ITerrainChannel channel = World.RequestModuleInterface<ITerrainChannel>(); | ||
10657 | 11684 | ||
10658 | bool checkTerrain = !((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) == ScriptBaseClass.RC_REJECT_LAND); | 11685 | bool checkTerrain = !((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) == ScriptBaseClass.RC_REJECT_LAND); |
10659 | bool checkAgents = !((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) == ScriptBaseClass.RC_REJECT_AGENTS); | 11686 | bool checkAgents = !((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) == ScriptBaseClass.RC_REJECT_AGENTS); |
10660 | bool checkNonPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) == ScriptBaseClass.RC_REJECT_NONPHYSICAL); | 11687 | bool checkNonPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) == ScriptBaseClass.RC_REJECT_NONPHYSICAL); |
10661 | bool checkPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) == ScriptBaseClass.RC_REJECT_PHYSICAL); | 11688 | bool checkPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) == ScriptBaseClass.RC_REJECT_PHYSICAL); |
10662 | 11689 | ||
10663 | for (float i = 0; i <= distance; i += 0.1f) | 11690 | if (checkTerrain) |
10664 | { | 11691 | { |
10665 | posToCheck = startvector + (dir * (i / (float)distance)); | 11692 | ContactResult? groundContact = GroundIntersection(rayStart, rayEnd); |
11693 | if (groundContact != null) | ||
11694 | results.Add((ContactResult)groundContact); | ||
11695 | } | ||
10666 | 11696 | ||
10667 | if (checkTerrain && channel[(int)(posToCheck.X + startvector.X), (int)(posToCheck.Y + startvector.Y)] < posToCheck.Z) | 11697 | if (checkAgents) |
10668 | { | 11698 | { |
10669 | ContactResult result = new ContactResult(); | 11699 | ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd); |
10670 | result.ConsumerID = 0; | 11700 | foreach (ContactResult r in agentHits) |
10671 | result.Depth = 0; | 11701 | results.Add(r); |
10672 | result.Normal = Vector3.Zero; | 11702 | } |
10673 | result.Pos = posToCheck; | ||
10674 | results.Add(result); | ||
10675 | checkTerrain = false; | ||
10676 | } | ||
10677 | 11703 | ||
10678 | if (checkAgents) | 11704 | if (checkPhysical || checkNonPhysical) |
10679 | { | 11705 | { |
10680 | World.ForEachRootScenePresence(delegate(ScenePresence sp) | 11706 | ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, checkPhysical, checkNonPhysical, detectPhantom); |
10681 | { | 11707 | foreach (ContactResult r in objectHits) |
10682 | if (sp.AbsolutePosition.ApproxEquals(posToCheck, sp.PhysicsActor.Size.X)) | 11708 | results.Add(r); |
10683 | { | ||
10684 | ContactResult result = new ContactResult (); | ||
10685 | result.ConsumerID = sp.LocalId; | ||
10686 | result.Depth = 0; | ||
10687 | result.Normal = Vector3.Zero; | ||
10688 | result.Pos = posToCheck; | ||
10689 | results.Add(result); | ||
10690 | } | ||
10691 | }); | ||
10692 | } | ||
10693 | } | 11709 | } |
10694 | 11710 | ||
10695 | int refcount = 0; | 11711 | results.Sort(delegate(ContactResult a, ContactResult b) |
11712 | { | ||
11713 | return (int)(a.Depth - b.Depth); | ||
11714 | }); | ||
11715 | |||
11716 | int values = 0; | ||
10696 | foreach (ContactResult result in results) | 11717 | foreach (ContactResult result in results) |
10697 | { | 11718 | { |
10698 | if ((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) | 11719 | if (result.Depth > dist) |
10699 | == ScriptBaseClass.RC_REJECT_LAND && result.ConsumerID == 0) | ||
10700 | continue; | 11720 | continue; |
10701 | 11721 | ||
10702 | ISceneEntity entity = World.GetSceneObjectPart(result.ConsumerID); | 11722 | UUID itemID = UUID.Zero; |
10703 | 11723 | int linkNum = 0; | |
10704 | if (entity == null && (rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) != ScriptBaseClass.RC_REJECT_AGENTS) | ||
10705 | entity = World.GetScenePresence(result.ConsumerID); //Only check if we should be looking for agents | ||
10706 | 11724 | ||
10707 | if (entity == null) | 11725 | SceneObjectPart part = World.GetSceneObjectPart(result.ConsumerID); |
11726 | // It's a prim! | ||
11727 | if (part != null) | ||
10708 | { | 11728 | { |
10709 | list.Add(UUID.Zero); | 11729 | if ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) == ScriptBaseClass.RC_GET_ROOT_KEY) |
10710 | 11730 | itemID = part.ParentGroup.UUID; | |
10711 | if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM) | 11731 | else |
10712 | list.Add(0); | 11732 | itemID = part.UUID; |
10713 | |||
10714 | list.Add(result.Pos); | ||
10715 | |||
10716 | if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL) | ||
10717 | list.Add(result.Normal); | ||
10718 | 11733 | ||
10719 | continue; //Can't find it, so add UUID.Zero | 11734 | linkNum = part.LinkNum; |
10720 | } | 11735 | } |
10721 | 11736 | else | |
10722 | /*if (detectPhantom == 0 && intersection.obj is ISceneChildEntity && | ||
10723 | ((ISceneChildEntity)intersection.obj).PhysActor == null) | ||
10724 | continue;*/ //Can't do this ATM, physics engine knows only of non phantom objects | ||
10725 | |||
10726 | if (entity is SceneObjectPart) | ||
10727 | { | 11737 | { |
10728 | if (((SceneObjectPart)entity).PhysActor != null && ((SceneObjectPart)entity).PhysActor.IsPhysical) | 11738 | ScenePresence sp = World.GetScenePresence(result.ConsumerID); |
10729 | { | 11739 | /// It it a boy? a girl? |
10730 | if (!checkPhysical) | 11740 | if (sp != null) |
10731 | continue; | 11741 | itemID = sp.UUID; |
10732 | } | ||
10733 | else | ||
10734 | { | ||
10735 | if (!checkNonPhysical) | ||
10736 | continue; | ||
10737 | } | ||
10738 | } | 11742 | } |
10739 | 11743 | ||
10740 | refcount++; | 11744 | list.Add(new LSL_String(itemID.ToString())); |
10741 | if ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) == ScriptBaseClass.RC_GET_ROOT_KEY && entity is SceneObjectPart) | 11745 | list.Add(new LSL_String(result.Pos.ToString())); |
10742 | list.Add(((SceneObjectPart)entity).ParentGroup.UUID); | ||
10743 | else | ||
10744 | list.Add(entity.UUID); | ||
10745 | 11746 | ||
10746 | if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM) | 11747 | if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM) |
10747 | { | 11748 | list.Add(new LSL_Integer(linkNum)); |
10748 | if (entity is SceneObjectPart) | ||
10749 | list.Add(((SceneObjectPart)entity).LinkNum); | ||
10750 | else | ||
10751 | list.Add(0); | ||
10752 | } | ||
10753 | 11749 | ||
10754 | list.Add(result.Pos); | ||
10755 | 11750 | ||
10756 | if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL) | 11751 | if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL) |
10757 | list.Add(result.Normal); | 11752 | list.Add(new LSL_Vector(result.Normal.X, result.Normal.Y, result.Normal.Z)); |
11753 | |||
11754 | values++; | ||
11755 | count--; | ||
11756 | |||
11757 | if (count == 0) | ||
11758 | break; | ||
10758 | } | 11759 | } |
10759 | 11760 | ||
10760 | list.Add(refcount); //The status code, either the # of contacts, RCERR_SIM_PERF_LOW, or RCERR_CAST_TIME_EXCEEDED | 11761 | list.Add(new LSL_Integer(values)); |
10761 | 11762 | ||
10762 | return list; | 11763 | return list; |
10763 | } | 11764 | } |
@@ -10797,7 +11798,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10797 | case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_ADD: | 11798 | case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_ADD: |
10798 | if (!isAccount) return 0; | 11799 | if (!isAccount) return 0; |
10799 | if (estate.HasAccess(id)) return 1; | 11800 | if (estate.HasAccess(id)) return 1; |
10800 | if (estate.IsBanned(id)) | 11801 | if (estate.IsBanned(id, World.GetUserFlags(id))) |
10801 | estate.RemoveBan(id); | 11802 | estate.RemoveBan(id); |
10802 | estate.AddEstateUser(id); | 11803 | estate.AddEstateUser(id); |
10803 | break; | 11804 | break; |
@@ -10816,14 +11817,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10816 | break; | 11817 | break; |
10817 | case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_ADD: | 11818 | case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_ADD: |
10818 | if (!isAccount) return 0; | 11819 | if (!isAccount) return 0; |
10819 | if (estate.IsBanned(id)) return 1; | 11820 | if (estate.IsBanned(id, World.GetUserFlags(id))) return 1; |
10820 | EstateBan ban = new EstateBan(); | 11821 | EstateBan ban = new EstateBan(); |
10821 | ban.EstateID = estate.EstateID; | 11822 | ban.EstateID = estate.EstateID; |
10822 | ban.BannedUserID = id; | 11823 | ban.BannedUserID = id; |
10823 | estate.AddBan(ban); | 11824 | estate.AddBan(ban); |
10824 | break; | 11825 | break; |
10825 | case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_REMOVE: | 11826 | case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_REMOVE: |
10826 | if (!isAccount || !estate.IsBanned(id)) return 0; | 11827 | if (!isAccount || !estate.IsBanned(id, World.GetUserFlags(id))) return 0; |
10827 | estate.RemoveBan(id); | 11828 | estate.RemoveBan(id); |
10828 | break; | 11829 | break; |
10829 | default: return 0; | 11830 | default: return 0; |
@@ -10849,22 +11850,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10849 | NotImplemented("llGetSPMaxMemory"); | 11850 | NotImplemented("llGetSPMaxMemory"); |
10850 | } | 11851 | } |
10851 | 11852 | ||
10852 | public void llGetUsedMemory() | 11853 | public virtual LSL_Integer llGetUsedMemory() |
10853 | { | 11854 | { |
10854 | m_host.AddScriptLPS(1); | 11855 | m_host.AddScriptLPS(1); |
10855 | NotImplemented("llGetUsedMemory"); | 11856 | NotImplemented("llGetUsedMemory"); |
11857 | return 0; | ||
10856 | } | 11858 | } |
10857 | 11859 | ||
10858 | public void llScriptProfiler(LSL_Integer flags) | 11860 | public void llScriptProfiler(LSL_Integer flags) |
10859 | { | 11861 | { |
10860 | m_host.AddScriptLPS(1); | 11862 | m_host.AddScriptLPS(1); |
10861 | NotImplemented("llScriptProfiler"); | 11863 | //NotImplemented("llScriptProfiler"); |
10862 | } | 11864 | } |
10863 | 11865 | ||
10864 | public void llSetSoundQueueing(int queue) | 11866 | public void llSetSoundQueueing(int queue) |
10865 | { | 11867 | { |
10866 | m_host.AddScriptLPS(1); | 11868 | m_host.AddScriptLPS(1); |
10867 | NotImplemented("llSetSoundQueueing"); | ||
10868 | } | 11869 | } |
10869 | 11870 | ||
10870 | public void llCollisionSprite(string impact_sprite) | 11871 | public void llCollisionSprite(string impact_sprite) |
@@ -10876,10 +11877,274 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10876 | public void llGodLikeRezObject(string inventory, LSL_Vector pos) | 11877 | public void llGodLikeRezObject(string inventory, LSL_Vector pos) |
10877 | { | 11878 | { |
10878 | m_host.AddScriptLPS(1); | 11879 | m_host.AddScriptLPS(1); |
10879 | NotImplemented("llGodLikeRezObject"); | 11880 | |
11881 | if (!World.Permissions.IsGod(m_host.OwnerID)) | ||
11882 | NotImplemented("llGodLikeRezObject"); | ||
11883 | |||
11884 | AssetBase rezAsset = World.AssetService.Get(inventory); | ||
11885 | if (rezAsset == null) | ||
11886 | { | ||
11887 | llSay(0, "Asset not found"); | ||
11888 | return; | ||
11889 | } | ||
11890 | |||
11891 | SceneObjectGroup group = null; | ||
11892 | |||
11893 | try | ||
11894 | { | ||
11895 | string xmlData = Utils.BytesToString(rezAsset.Data); | ||
11896 | group = SceneObjectSerializer.FromOriginalXmlFormat(xmlData); | ||
11897 | } | ||
11898 | catch | ||
11899 | { | ||
11900 | llSay(0, "Asset not found"); | ||
11901 | return; | ||
11902 | } | ||
11903 | |||
11904 | if (group == null) | ||
11905 | { | ||
11906 | llSay(0, "Asset not found"); | ||
11907 | return; | ||
11908 | } | ||
11909 | |||
11910 | group.RootPart.AttachPoint = group.RootPart.Shape.State; | ||
11911 | group.RootPart.AttachOffset = group.AbsolutePosition; | ||
11912 | |||
11913 | group.ResetIDs(); | ||
11914 | |||
11915 | Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z); | ||
11916 | World.AddNewSceneObject(group, true, llpos, Quaternion.Identity, Vector3.Zero); | ||
11917 | group.CreateScriptInstances(0, true, World.DefaultScriptEngine, 3); | ||
11918 | group.ScheduleGroupForFullUpdate(); | ||
11919 | |||
11920 | // objects rezzed with this method are die_at_edge by default. | ||
11921 | group.RootPart.SetDieAtEdge(true); | ||
11922 | |||
11923 | group.ResumeScripts(); | ||
11924 | |||
11925 | m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams( | ||
11926 | "object_rez", new Object[] { | ||
11927 | new LSL_String( | ||
11928 | group.RootPart.UUID.ToString()) }, | ||
11929 | new DetectParams[0])); | ||
11930 | } | ||
11931 | |||
11932 | public LSL_String llTransferLindenDollars(string destination, int amount) | ||
11933 | { | ||
11934 | UUID txn = UUID.Random(); | ||
11935 | |||
11936 | Util.FireAndForget(delegate(object x) | ||
11937 | { | ||
11938 | int replycode = 0; | ||
11939 | string replydata = destination + "," + amount.ToString(); | ||
11940 | |||
11941 | try | ||
11942 | { | ||
11943 | UUID invItemID=InventorySelf(); | ||
11944 | if (invItemID == UUID.Zero) | ||
11945 | { | ||
11946 | replydata = "SERVICE_ERROR"; | ||
11947 | return; | ||
11948 | } | ||
11949 | |||
11950 | m_host.AddScriptLPS(1); | ||
11951 | |||
11952 | m_host.TaskInventory.LockItemsForRead(true); | ||
11953 | TaskInventoryItem item = m_host.TaskInventory[invItemID]; | ||
11954 | m_host.TaskInventory.LockItemsForRead(false); | ||
11955 | |||
11956 | if (item.PermsGranter == UUID.Zero) | ||
11957 | { | ||
11958 | replydata = "MISSING_PERMISSION_DEBIT"; | ||
11959 | return; | ||
11960 | } | ||
11961 | |||
11962 | if ((item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0) | ||
11963 | { | ||
11964 | replydata = "MISSING_PERMISSION_DEBIT"; | ||
11965 | return; | ||
11966 | } | ||
11967 | |||
11968 | UUID toID = new UUID(); | ||
11969 | |||
11970 | if (!UUID.TryParse(destination, out toID)) | ||
11971 | { | ||
11972 | replydata = "INVALID_AGENT"; | ||
11973 | return; | ||
11974 | } | ||
11975 | |||
11976 | IMoneyModule money = World.RequestModuleInterface<IMoneyModule>(); | ||
11977 | |||
11978 | if (money == null) | ||
11979 | { | ||
11980 | replydata = "TRANSFERS_DISABLED"; | ||
11981 | return; | ||
11982 | } | ||
11983 | |||
11984 | bool result = money.ObjectGiveMoney( | ||
11985 | m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount); | ||
11986 | |||
11987 | if (result) | ||
11988 | { | ||
11989 | replycode = 1; | ||
11990 | return; | ||
11991 | } | ||
11992 | |||
11993 | replydata = "LINDENDOLLAR_INSUFFICIENTFUNDS"; | ||
11994 | } | ||
11995 | finally | ||
11996 | { | ||
11997 | m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( | ||
11998 | "transaction_result", new Object[] { | ||
11999 | new LSL_String(txn.ToString()), | ||
12000 | new LSL_Integer(replycode), | ||
12001 | new LSL_String(replydata) }, | ||
12002 | new DetectParams[0])); | ||
12003 | } | ||
12004 | }); | ||
12005 | |||
12006 | return txn.ToString(); | ||
10880 | } | 12007 | } |
10881 | 12008 | ||
10882 | #endregion | 12009 | #endregion |
12010 | |||
12011 | public void llSetKeyframedMotion(LSL_List frames, LSL_List options) | ||
12012 | { | ||
12013 | SceneObjectGroup group = m_host.ParentGroup; | ||
12014 | |||
12015 | if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical) | ||
12016 | return; | ||
12017 | if (group.IsAttachment) | ||
12018 | return; | ||
12019 | |||
12020 | if (frames.Data.Length > 0) // We are getting a new motion | ||
12021 | { | ||
12022 | if (group.RootPart.KeyframeMotion != null) | ||
12023 | group.RootPart.KeyframeMotion.Stop(); | ||
12024 | group.RootPart.KeyframeMotion = null; | ||
12025 | |||
12026 | int idx = 0; | ||
12027 | |||
12028 | KeyframeMotion.PlayMode mode = KeyframeMotion.PlayMode.Forward; | ||
12029 | KeyframeMotion.DataFormat data = KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation; | ||
12030 | |||
12031 | while (idx < options.Data.Length) | ||
12032 | { | ||
12033 | int option = (int)options.GetLSLIntegerItem(idx++); | ||
12034 | int remain = options.Data.Length - idx; | ||
12035 | |||
12036 | switch (option) | ||
12037 | { | ||
12038 | case ScriptBaseClass.KFM_MODE: | ||
12039 | if (remain < 1) | ||
12040 | break; | ||
12041 | int modeval = (int)options.GetLSLIntegerItem(idx++); | ||
12042 | switch(modeval) | ||
12043 | { | ||
12044 | case ScriptBaseClass.KFM_FORWARD: | ||
12045 | mode = KeyframeMotion.PlayMode.Forward; | ||
12046 | break; | ||
12047 | case ScriptBaseClass.KFM_REVERSE: | ||
12048 | mode = KeyframeMotion.PlayMode.Reverse; | ||
12049 | break; | ||
12050 | case ScriptBaseClass.KFM_LOOP: | ||
12051 | mode = KeyframeMotion.PlayMode.Loop; | ||
12052 | break; | ||
12053 | case ScriptBaseClass.KFM_PING_PONG: | ||
12054 | mode = KeyframeMotion.PlayMode.PingPong; | ||
12055 | break; | ||
12056 | } | ||
12057 | break; | ||
12058 | case ScriptBaseClass.KFM_DATA: | ||
12059 | if (remain < 1) | ||
12060 | break; | ||
12061 | int dataval = (int)options.GetLSLIntegerItem(idx++); | ||
12062 | data = (KeyframeMotion.DataFormat)dataval; | ||
12063 | break; | ||
12064 | } | ||
12065 | } | ||
12066 | |||
12067 | group.RootPart.KeyframeMotion = new KeyframeMotion(group, mode, data); | ||
12068 | |||
12069 | idx = 0; | ||
12070 | |||
12071 | int elemLength = 2; | ||
12072 | if (data == (KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation)) | ||
12073 | elemLength = 3; | ||
12074 | |||
12075 | List<KeyframeMotion.Keyframe> keyframes = new List<KeyframeMotion.Keyframe>(); | ||
12076 | while (idx < frames.Data.Length) | ||
12077 | { | ||
12078 | int remain = frames.Data.Length - idx; | ||
12079 | |||
12080 | if (remain < elemLength) | ||
12081 | break; | ||
12082 | |||
12083 | KeyframeMotion.Keyframe frame = new KeyframeMotion.Keyframe(); | ||
12084 | frame.Position = null; | ||
12085 | frame.Rotation = null; | ||
12086 | |||
12087 | if ((data & KeyframeMotion.DataFormat.Translation) != 0) | ||
12088 | { | ||
12089 | LSL_Types.Vector3 tempv = frames.GetVector3Item(idx++); | ||
12090 | frame.Position = new Vector3((float)tempv.x, (float)tempv.y, (float)tempv.z); | ||
12091 | } | ||
12092 | if ((data & KeyframeMotion.DataFormat.Rotation) != 0) | ||
12093 | { | ||
12094 | LSL_Types.Quaternion tempq = frames.GetQuaternionItem(idx++); | ||
12095 | frame.Rotation = new Quaternion((float)tempq.x, (float)tempq.y, (float)tempq.z, (float)tempq.s); | ||
12096 | } | ||
12097 | |||
12098 | float tempf = (float)frames.GetLSLFloatItem(idx++); | ||
12099 | frame.TimeMS = (int)(tempf * 1000.0f); | ||
12100 | |||
12101 | keyframes.Add(frame); | ||
12102 | } | ||
12103 | |||
12104 | group.RootPart.KeyframeMotion.SetKeyframes(keyframes.ToArray()); | ||
12105 | group.RootPart.KeyframeMotion.Start(); | ||
12106 | } | ||
12107 | else | ||
12108 | { | ||
12109 | if (group.RootPart.KeyframeMotion == null) | ||
12110 | return; | ||
12111 | |||
12112 | if (options.Data.Length == 0) | ||
12113 | { | ||
12114 | group.RootPart.KeyframeMotion.Stop(); | ||
12115 | return; | ||
12116 | } | ||
12117 | |||
12118 | int code = (int)options.GetLSLIntegerItem(0); | ||
12119 | |||
12120 | int idx = 0; | ||
12121 | |||
12122 | while (idx < options.Data.Length) | ||
12123 | { | ||
12124 | int option = (int)options.GetLSLIntegerItem(idx++); | ||
12125 | int remain = options.Data.Length - idx; | ||
12126 | |||
12127 | switch (option) | ||
12128 | { | ||
12129 | case ScriptBaseClass.KFM_COMMAND: | ||
12130 | int cmd = (int)options.GetLSLIntegerItem(idx++); | ||
12131 | switch (cmd) | ||
12132 | { | ||
12133 | case ScriptBaseClass.KFM_CMD_PLAY: | ||
12134 | group.RootPart.KeyframeMotion.Start(); | ||
12135 | break; | ||
12136 | case ScriptBaseClass.KFM_CMD_STOP: | ||
12137 | group.RootPart.KeyframeMotion.Stop(); | ||
12138 | break; | ||
12139 | case ScriptBaseClass.KFM_CMD_PAUSE: | ||
12140 | group.RootPart.KeyframeMotion.Pause(); | ||
12141 | break; | ||
12142 | } | ||
12143 | break; | ||
12144 | } | ||
12145 | } | ||
12146 | } | ||
12147 | } | ||
10883 | } | 12148 | } |
10884 | 12149 | ||
10885 | public class NotecardCache | 12150 | public class NotecardCache |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 8edd146..ecc5fb5 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | |||
@@ -137,6 +137,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
137 | internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow; | 137 | internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow; |
138 | internal float m_ScriptDelayFactor = 1.0f; | 138 | internal float m_ScriptDelayFactor = 1.0f; |
139 | internal float m_ScriptDistanceFactor = 1.0f; | 139 | internal float m_ScriptDistanceFactor = 1.0f; |
140 | internal bool m_debuggerSafe = false; | ||
140 | internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >(); | 141 | internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >(); |
141 | 142 | ||
142 | public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) | 143 | public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) |
@@ -145,6 +146,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
145 | m_host = host; | 146 | m_host = host; |
146 | m_localID = localID; | 147 | m_localID = localID; |
147 | m_itemID = itemID; | 148 | m_itemID = itemID; |
149 | m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false); | ||
148 | 150 | ||
149 | if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false)) | 151 | if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false)) |
150 | m_OSFunctionsEnabled = true; | 152 | m_OSFunctionsEnabled = true; |
@@ -206,7 +208,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
206 | 208 | ||
207 | internal void OSSLError(string msg) | 209 | internal void OSSLError(string msg) |
208 | { | 210 | { |
209 | throw new Exception("OSSL Runtime Error: " + msg); | 211 | if (m_debuggerSafe) |
212 | { | ||
213 | OSSLShoutError(msg); | ||
214 | } | ||
215 | else | ||
216 | { | ||
217 | throw new Exception("OSSL Runtime Error: " + msg); | ||
218 | } | ||
210 | } | 219 | } |
211 | 220 | ||
212 | private void InitLSL() | 221 | private void InitLSL() |
@@ -917,18 +926,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
917 | if (target != null) | 926 | if (target != null) |
918 | { | 927 | { |
919 | UUID animID=UUID.Zero; | 928 | UUID animID=UUID.Zero; |
920 | lock (m_host.TaskInventory) | 929 | m_host.TaskInventory.LockItemsForRead(true); |
930 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | ||
921 | { | 931 | { |
922 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | 932 | if (inv.Value.Name == animation) |
923 | { | 933 | { |
924 | if (inv.Value.Name == animation) | 934 | if (inv.Value.Type == (int)AssetType.Animation) |
925 | { | 935 | animID = inv.Value.AssetID; |
926 | if (inv.Value.Type == (int)AssetType.Animation) | 936 | continue; |
927 | animID = inv.Value.AssetID; | ||
928 | continue; | ||
929 | } | ||
930 | } | 937 | } |
931 | } | 938 | } |
939 | m_host.TaskInventory.LockItemsForRead(false); | ||
932 | if (animID == UUID.Zero) | 940 | if (animID == UUID.Zero) |
933 | target.Animator.AddAnimation(animation, m_host.UUID); | 941 | target.Animator.AddAnimation(animation, m_host.UUID); |
934 | else | 942 | else |
@@ -955,18 +963,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
955 | if (target != null) | 963 | if (target != null) |
956 | { | 964 | { |
957 | UUID animID = UUID.Zero; | 965 | UUID animID = UUID.Zero; |
958 | lock (m_host.TaskInventory) | 966 | m_host.TaskInventory.LockItemsForRead(true); |
967 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | ||
959 | { | 968 | { |
960 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | 969 | if (inv.Value.Name == animation) |
961 | { | 970 | { |
962 | if (inv.Value.Name == animation) | 971 | if (inv.Value.Type == (int)AssetType.Animation) |
963 | { | 972 | animID = inv.Value.AssetID; |
964 | if (inv.Value.Type == (int)AssetType.Animation) | 973 | continue; |
965 | animID = inv.Value.AssetID; | ||
966 | continue; | ||
967 | } | ||
968 | } | 974 | } |
969 | } | 975 | } |
976 | m_host.TaskInventory.LockItemsForRead(false); | ||
970 | 977 | ||
971 | if (animID == UUID.Zero) | 978 | if (animID == UUID.Zero) |
972 | target.Animator.RemoveAnimation(animation); | 979 | target.Animator.RemoveAnimation(animation); |
@@ -1798,6 +1805,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1798 | 1805 | ||
1799 | if (!UUID.TryParse(notecardNameOrUuid, out assetID)) | 1806 | if (!UUID.TryParse(notecardNameOrUuid, out assetID)) |
1800 | { | 1807 | { |
1808 | m_host.TaskInventory.LockItemsForRead(true); | ||
1801 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | 1809 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) |
1802 | { | 1810 | { |
1803 | if (item.Type == 7 && item.Name == notecardNameOrUuid) | 1811 | if (item.Type == 7 && item.Name == notecardNameOrUuid) |
@@ -1805,6 +1813,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1805 | assetID = item.AssetID; | 1813 | assetID = item.AssetID; |
1806 | } | 1814 | } |
1807 | } | 1815 | } |
1816 | m_host.TaskInventory.LockItemsForRead(false); | ||
1808 | } | 1817 | } |
1809 | 1818 | ||
1810 | if (assetID == UUID.Zero) | 1819 | if (assetID == UUID.Zero) |
@@ -2258,7 +2267,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2258 | CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); | 2267 | CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); |
2259 | m_host.AddScriptLPS(1); | 2268 | m_host.AddScriptLPS(1); |
2260 | 2269 | ||
2261 | return NpcCreate(firstname, lastname, position, notecard, false, false); | 2270 | return NpcCreate(firstname, lastname, position, notecard, true, false); |
2262 | } | 2271 | } |
2263 | 2272 | ||
2264 | public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options) | 2273 | public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options) |
@@ -2269,24 +2278,39 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2269 | return NpcCreate( | 2278 | return NpcCreate( |
2270 | firstname, lastname, position, notecard, | 2279 | firstname, lastname, position, notecard, |
2271 | (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0, | 2280 | (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0, |
2272 | (options & ScriptBaseClass.OS_NPC_SENSE_AS_AGENT) != 0); | 2281 | false); |
2282 | // (options & ScriptBaseClass.OS_NPC_SENSE_AS_AGENT) != 0); | ||
2273 | } | 2283 | } |
2274 | 2284 | ||
2275 | private LSL_Key NpcCreate( | 2285 | private LSL_Key NpcCreate( |
2276 | string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent) | 2286 | string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent) |
2277 | { | 2287 | { |
2288 | if (!owned) | ||
2289 | OSSLError("Unowned NPCs are unsupported"); | ||
2290 | |||
2291 | string groupTitle = String.Empty; | ||
2292 | |||
2293 | if (!World.Permissions.CanRezObject(1, m_host.OwnerID, new Vector3((float)position.x, (float)position.y, (float)position.z))) | ||
2294 | return new LSL_Key(UUID.Zero.ToString()); | ||
2295 | |||
2296 | if (firstname != String.Empty || lastname != String.Empty) | ||
2297 | { | ||
2298 | if (firstname != "Shown outfit:") | ||
2299 | groupTitle = "- NPC -"; | ||
2300 | } | ||
2301 | |||
2278 | INPCModule module = World.RequestModuleInterface<INPCModule>(); | 2302 | INPCModule module = World.RequestModuleInterface<INPCModule>(); |
2279 | if (module != null) | 2303 | if (module != null) |
2280 | { | 2304 | { |
2281 | AvatarAppearance appearance = null; | 2305 | AvatarAppearance appearance = null; |
2282 | 2306 | ||
2283 | UUID id; | 2307 | // UUID id; |
2284 | if (UUID.TryParse(notecard, out id)) | 2308 | // if (UUID.TryParse(notecard, out id)) |
2285 | { | 2309 | // { |
2286 | ScenePresence clonePresence = World.GetScenePresence(id); | 2310 | // ScenePresence clonePresence = World.GetScenePresence(id); |
2287 | if (clonePresence != null) | 2311 | // if (clonePresence != null) |
2288 | appearance = clonePresence.Appearance; | 2312 | // appearance = clonePresence.Appearance; |
2289 | } | 2313 | // } |
2290 | 2314 | ||
2291 | if (appearance == null) | 2315 | if (appearance == null) |
2292 | { | 2316 | { |
@@ -2314,6 +2338,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2314 | World, | 2338 | World, |
2315 | appearance); | 2339 | appearance); |
2316 | 2340 | ||
2341 | ScenePresence sp; | ||
2342 | if (World.TryGetScenePresence(x, out sp)) | ||
2343 | { | ||
2344 | sp.Grouptitle = groupTitle; | ||
2345 | sp.SendAvatarDataToAllAgents(); | ||
2346 | } | ||
2317 | return new LSL_Key(x.ToString()); | 2347 | return new LSL_Key(x.ToString()); |
2318 | } | 2348 | } |
2319 | 2349 | ||
@@ -2582,16 +2612,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2582 | CheckThreatLevel(ThreatLevel.High, "osNpcRemove"); | 2612 | CheckThreatLevel(ThreatLevel.High, "osNpcRemove"); |
2583 | m_host.AddScriptLPS(1); | 2613 | m_host.AddScriptLPS(1); |
2584 | 2614 | ||
2585 | INPCModule module = World.RequestModuleInterface<INPCModule>(); | 2615 | ManualResetEvent ev = new ManualResetEvent(false); |
2586 | if (module != null) | ||
2587 | { | ||
2588 | UUID npcId = new UUID(npc.m_string); | ||
2589 | 2616 | ||
2590 | if (!module.CheckPermissions(npcId, m_host.OwnerID)) | 2617 | Util.FireAndForget(delegate(object x) { |
2591 | return; | 2618 | try |
2619 | { | ||
2620 | INPCModule module = World.RequestModuleInterface<INPCModule>(); | ||
2621 | if (module != null) | ||
2622 | { | ||
2623 | UUID npcId = new UUID(npc.m_string); | ||
2592 | 2624 | ||
2593 | module.DeleteNPC(npcId, World); | 2625 | ILandObject l = World.LandChannel.GetLandObject(m_host.GroupPosition.X, m_host.GroupPosition.Y); |
2594 | } | 2626 | if (l == null || m_host.OwnerID != l.LandData.OwnerID) |
2627 | { | ||
2628 | if (!module.CheckPermissions(npcId, m_host.OwnerID)) | ||
2629 | return; | ||
2630 | } | ||
2631 | |||
2632 | module.DeleteNPC(npcId, World); | ||
2633 | } | ||
2634 | } | ||
2635 | finally | ||
2636 | { | ||
2637 | ev.Set(); | ||
2638 | } | ||
2639 | }); | ||
2640 | ev.WaitOne(); | ||
2595 | } | 2641 | } |
2596 | 2642 | ||
2597 | public void osNpcPlayAnimation(LSL_Key npc, string animation) | 2643 | public void osNpcPlayAnimation(LSL_Key npc, string animation) |
@@ -2944,4 +2990,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2944 | return date.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"); | 2990 | return date.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"); |
2945 | } | 2991 | } |
2946 | } | 2992 | } |
2947 | } \ No newline at end of file | 2993 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs index 1c272f8..1373971 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs | |||
@@ -222,7 +222,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
222 | // Is the sensor type is AGENT and not SCRIPTED then include agents | 222 | // Is the sensor type is AGENT and not SCRIPTED then include agents |
223 | if ((ts.type & (AGENT | AGENT_BY_USERNAME | NPC)) != 0 && (ts.type & SCRIPTED) == 0) | 223 | if ((ts.type & (AGENT | AGENT_BY_USERNAME | NPC)) != 0 && (ts.type & SCRIPTED) == 0) |
224 | { | 224 | { |
225 | sensedEntities.AddRange(doAgentSensor(ts)); | 225 | sensedEntities.AddRange(doAgentSensor(ts)); |
226 | } | 226 | } |
227 | 227 | ||
228 | // If SCRIPTED or PASSIVE or ACTIVE check objects | 228 | // If SCRIPTED or PASSIVE or ACTIVE check objects |
@@ -319,13 +319,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
319 | float dy; | 319 | float dy; |
320 | float dz; | 320 | float dz; |
321 | 321 | ||
322 | Quaternion q = SensePoint.RotationOffset; | 322 | // Quaternion q = SensePoint.RotationOffset; |
323 | Quaternion q = SensePoint.GetWorldRotation(); // non-attached prim Sensor *always* uses World rotation! | ||
323 | if (SensePoint.ParentGroup.IsAttachment) | 324 | if (SensePoint.ParentGroup.IsAttachment) |
324 | { | 325 | { |
325 | // In attachments, the sensor cone always orients with the | 326 | // In attachments, the sensor cone always orients with the |
326 | // avatar rotation. This may include a nonzero elevation if | 327 | // avatar rotation. This may include a nonzero elevation if |
327 | // in mouselook. | 328 | // in mouselook. |
328 | ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar); | 329 | ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar); |
330 | fromRegionPos = avatar.AbsolutePosition; | ||
329 | q = avatar.Rotation; | 331 | q = avatar.Rotation; |
330 | } | 332 | } |
331 | LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W); | 333 | LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W); |
@@ -448,6 +450,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
448 | // avatar rotation. This may include a nonzero elevation if | 450 | // avatar rotation. This may include a nonzero elevation if |
449 | // in mouselook. | 451 | // in mouselook. |
450 | ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar); | 452 | ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar); |
453 | if (avatar == null) | ||
454 | return sensedEntities; | ||
455 | fromRegionPos = avatar.AbsolutePosition; | ||
451 | q = avatar.Rotation; | 456 | q = avatar.Rotation; |
452 | } | 457 | } |
453 | 458 | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs index bc63030..9ee6946 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs | |||
@@ -118,25 +118,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
118 | if (Timers.Count == 0) | 118 | if (Timers.Count == 0) |
119 | return; | 119 | return; |
120 | 120 | ||
121 | Dictionary<string, TimerClass>.ValueCollection tvals; | ||
121 | lock (TimerListLock) | 122 | lock (TimerListLock) |
122 | { | 123 | { |
123 | // Go through all timers | 124 | // Go through all timers |
124 | Dictionary<string, TimerClass>.ValueCollection tvals = Timers.Values; | 125 | tvals = Timers.Values; |
125 | foreach (TimerClass ts in tvals) | 126 | } |
127 | |||
128 | foreach (TimerClass ts in tvals) | ||
129 | { | ||
130 | // Time has passed? | ||
131 | if (ts.next < DateTime.Now.Ticks) | ||
126 | { | 132 | { |
127 | // Time has passed? | 133 | //m_log.Debug("Time has passed: Now: " + DateTime.Now.Ticks + ", Passed: " + ts.next); |
128 | if (ts.next < DateTime.Now.Ticks) | 134 | // Add it to queue |
129 | { | 135 | m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID, |
130 | //m_log.Debug("Time has passed: Now: " + DateTime.Now.Ticks + ", Passed: " + ts.next); | 136 | new EventParams("timer", new Object[0], |
131 | // Add it to queue | 137 | new DetectParams[0])); |
132 | m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID, | 138 | // set next interval |
133 | new EventParams("timer", new Object[0], | 139 | |
134 | new DetectParams[0])); | 140 | //ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval); |
135 | // set next interval | 141 | ts.next = DateTime.Now.Ticks + ts.interval; |
136 | |||
137 | //ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval); | ||
138 | ts.next = DateTime.Now.Ticks + ts.interval; | ||
139 | } | ||
140 | } | 142 | } |
141 | } | 143 | } |
142 | } | 144 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ICM_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ICM_Api.cs new file mode 100644 index 0000000..ab215f3 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ICM_Api.cs | |||
@@ -0,0 +1,46 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections; | ||
29 | using OpenSim.Region.ScriptEngine.Interfaces; | ||
30 | |||
31 | using key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; | ||
32 | using rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion; | ||
33 | using vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; | ||
34 | using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list; | ||
35 | using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; | ||
36 | using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; | ||
37 | using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat; | ||
38 | |||
39 | namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | ||
40 | { | ||
41 | public interface ICM_Api | ||
42 | { | ||
43 | string cmDetectedCountry(int num); | ||
44 | string cmGetAgentCountry(key key); | ||
45 | } | ||
46 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs index 0f53bc3..8d97a7c 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs | |||
@@ -124,6 +124,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
124 | LSL_Float llGetEnergy(); | 124 | LSL_Float llGetEnergy(); |
125 | LSL_Vector llGetForce(); | 125 | LSL_Vector llGetForce(); |
126 | LSL_Integer llGetFreeMemory(); | 126 | LSL_Integer llGetFreeMemory(); |
127 | LSL_Integer llGetUsedMemory(); | ||
127 | LSL_Integer llGetFreeURLs(); | 128 | LSL_Integer llGetFreeURLs(); |
128 | LSL_Vector llGetGeometricCenter(); | 129 | LSL_Vector llGetGeometricCenter(); |
129 | LSL_Float llGetGMTclock(); | 130 | LSL_Float llGetGMTclock(); |
@@ -203,6 +204,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
203 | void llGiveInventory(string destination, string inventory); | 204 | void llGiveInventory(string destination, string inventory); |
204 | void llGiveInventoryList(string destination, string category, LSL_List inventory); | 205 | void llGiveInventoryList(string destination, string category, LSL_List inventory); |
205 | LSL_Integer llGiveMoney(string destination, int amount); | 206 | LSL_Integer llGiveMoney(string destination, int amount); |
207 | LSL_String llTransferLindenDollars(string destination, int amount); | ||
206 | void llGodLikeRezObject(string inventory, LSL_Vector pos); | 208 | void llGodLikeRezObject(string inventory, LSL_Vector pos); |
207 | LSL_Float llGround(LSL_Vector offset); | 209 | LSL_Float llGround(LSL_Vector offset); |
208 | LSL_Vector llGroundContour(LSL_Vector offset); | 210 | LSL_Vector llGroundContour(LSL_Vector offset); |
@@ -348,6 +350,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
348 | void llSetParcelMusicURL(string url); | 350 | void llSetParcelMusicURL(string url); |
349 | void llSetPayPrice(int price, LSL_List quick_pay_buttons); | 351 | void llSetPayPrice(int price, LSL_List quick_pay_buttons); |
350 | void llSetPos(LSL_Vector pos); | 352 | void llSetPos(LSL_Vector pos); |
353 | LSL_Integer llSetRegionPos(LSL_Vector pos); | ||
351 | LSL_Integer llSetPrimMediaParams(LSL_Integer face, LSL_List rules); | 354 | LSL_Integer llSetPrimMediaParams(LSL_Integer face, LSL_List rules); |
352 | void llSetPrimitiveParams(LSL_List rules); | 355 | void llSetPrimitiveParams(LSL_List rules); |
353 | void llSetLinkPrimitiveParamsFast(int linknum, LSL_List rules); | 356 | void llSetLinkPrimitiveParamsFast(int linknum, LSL_List rules); |
@@ -396,6 +399,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
396 | void llTargetOmega(LSL_Vector axis, double spinrate, double gain); | 399 | void llTargetOmega(LSL_Vector axis, double spinrate, double gain); |
397 | void llTargetRemove(int number); | 400 | void llTargetRemove(int number); |
398 | void llTeleportAgentHome(string agent); | 401 | void llTeleportAgentHome(string agent); |
402 | void llTeleportAgent(string agent, string simname, LSL_Vector pos, LSL_Vector lookAt); | ||
399 | void llTextBox(string avatar, string message, int chat_channel); | 403 | void llTextBox(string avatar, string message, int chat_channel); |
400 | LSL_String llToLower(string source); | 404 | LSL_String llToLower(string source); |
401 | LSL_String llToUpper(string source); | 405 | LSL_String llToUpper(string source); |
@@ -412,9 +416,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
412 | LSL_Vector llWind(LSL_Vector offset); | 416 | LSL_Vector llWind(LSL_Vector offset); |
413 | LSL_String llXorBase64Strings(string str1, string str2); | 417 | LSL_String llXorBase64Strings(string str1, string str2); |
414 | LSL_String llXorBase64StringsCorrect(string str1, string str2); | 418 | LSL_String llXorBase64StringsCorrect(string str1, string str2); |
415 | void print(string str); | 419 | LSL_Integer llGetLinkNumberOfSides(LSL_Integer link); |
416 | 420 | ||
417 | void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules); | 421 | void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules); |
418 | LSL_List GetLinkPrimitiveParamsEx(LSL_Key prim, LSL_List rules); | 422 | LSL_List GetLinkPrimitiveParamsEx(LSL_Key prim, LSL_List rules); |
423 | void llSetKeyframedMotion(LSL_List frames, LSL_List options); | ||
419 | } | 424 | } |
420 | } | 425 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index 82a6caf..fb52600 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | |||
@@ -85,7 +85,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
85 | // Avatar Info Commands | 85 | // Avatar Info Commands |
86 | string osGetAgentIP(string agent); | 86 | string osGetAgentIP(string agent); |
87 | LSL_List osGetAgents(); | 87 | LSL_List osGetAgents(); |
88 | 88 | ||
89 | // Teleport commands | 89 | // Teleport commands |
90 | void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat); | 90 | void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat); |
91 | void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat); | 91 | void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat); |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Stub.cs new file mode 100644 index 0000000..4132dfa --- /dev/null +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Stub.cs | |||
@@ -0,0 +1,71 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Runtime.Remoting.Lifetime; | ||
30 | using System.Threading; | ||
31 | using System.Reflection; | ||
32 | using System.Collections; | ||
33 | using System.Collections.Generic; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Region.Framework.Interfaces; | ||
36 | using OpenSim.Region.ScriptEngine.Interfaces; | ||
37 | using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces; | ||
38 | using integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; | ||
39 | using vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; | ||
40 | using rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion; | ||
41 | using key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; | ||
42 | using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list; | ||
43 | using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; | ||
44 | using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat; | ||
45 | using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; | ||
46 | |||
47 | namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | ||
48 | { | ||
49 | public partial class ScriptBaseClass : MarshalByRefObject | ||
50 | { | ||
51 | public ICM_Api m_CM_Functions; | ||
52 | |||
53 | public void ApiTypeCM(IScriptApi api) | ||
54 | { | ||
55 | if (!(api is ICM_Api)) | ||
56 | return; | ||
57 | |||
58 | m_CM_Functions = (ICM_Api)api; | ||
59 | } | ||
60 | |||
61 | public string cmDetectedCountry(int num) | ||
62 | { | ||
63 | return m_CM_Functions.cmDetectedCountry(num); | ||
64 | } | ||
65 | |||
66 | public string cmGetAgentCountry(key key) | ||
67 | { | ||
68 | return m_CM_Functions.cmGetAgentCountry(key); | ||
69 | } | ||
70 | } | ||
71 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs index 9615315..943d7a2 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs | |||
@@ -27,6 +27,7 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Diagnostics; //for [DebuggerNonUserCode] | ||
30 | using System.Reflection; | 31 | using System.Reflection; |
31 | using System.Runtime.Remoting.Lifetime; | 32 | using System.Runtime.Remoting.Lifetime; |
32 | using OpenSim.Region.ScriptEngine.Shared; | 33 | using OpenSim.Region.ScriptEngine.Shared; |
@@ -132,6 +133,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
132 | return (eventFlags); | 133 | return (eventFlags); |
133 | } | 134 | } |
134 | 135 | ||
136 | [DebuggerNonUserCode] | ||
135 | public void ExecuteEvent(string state, string FunctionName, object[] args) | 137 | public void ExecuteEvent(string state, string FunctionName, object[] args) |
136 | { | 138 | { |
137 | // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory. | 139 | // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory. |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs index 5a53e15..a5e160d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs | |||
@@ -282,6 +282,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
282 | public const int CHANGED_REGION_START = 1024; //LL Changed the constant from CHANGED_REGION_RESTART | 282 | public const int CHANGED_REGION_START = 1024; //LL Changed the constant from CHANGED_REGION_RESTART |
283 | public const int CHANGED_MEDIA = 2048; | 283 | public const int CHANGED_MEDIA = 2048; |
284 | public const int CHANGED_ANIMATION = 16384; | 284 | public const int CHANGED_ANIMATION = 16384; |
285 | public const int CHANGED_POSITION = 32768; | ||
285 | public const int TYPE_INVALID = 0; | 286 | public const int TYPE_INVALID = 0; |
286 | public const int TYPE_INTEGER = 1; | 287 | public const int TYPE_INTEGER = 1; |
287 | public const int TYPE_FLOAT = 2; | 288 | public const int TYPE_FLOAT = 2; |
@@ -640,5 +641,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
640 | public static readonly LSLInteger RCERR_UNKNOWN = -1; | 641 | public static readonly LSLInteger RCERR_UNKNOWN = -1; |
641 | public static readonly LSLInteger RCERR_SIM_PERF_LOW = -2; | 642 | public static readonly LSLInteger RCERR_SIM_PERF_LOW = -2; |
642 | public static readonly LSLInteger RCERR_CAST_TIME_EXCEEDED = 3; | 643 | public static readonly LSLInteger RCERR_CAST_TIME_EXCEEDED = 3; |
644 | |||
645 | public const int KFM_MODE = 1; | ||
646 | public const int KFM_LOOP = 1; | ||
647 | public const int KFM_REVERSE = 3; | ||
648 | public const int KFM_FORWARD = 0; | ||
649 | public const int KFM_PING_PONG = 2; | ||
650 | public const int KFM_DATA = 2; | ||
651 | public const int KFM_TRANSLATION = 2; | ||
652 | public const int KFM_ROTATION = 1; | ||
653 | public const int KFM_COMMAND = 0; | ||
654 | public const int KFM_CMD_PLAY = 0; | ||
655 | public const int KFM_CMD_STOP = 1; | ||
656 | public const int KFM_CMD_PAUSE = 2; | ||
643 | } | 657 | } |
644 | } | 658 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs index f8e3c36..a8d1ddb 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs | |||
@@ -26,6 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Diagnostics; //for [DebuggerNonUserCode] | ||
29 | using System.Runtime.Remoting.Lifetime; | 30 | using System.Runtime.Remoting.Lifetime; |
30 | using System.Threading; | 31 | using System.Threading; |
31 | using System.Reflection; | 32 | using System.Reflection; |
@@ -164,6 +165,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
164 | m_LSL_Functions.llBreakLink(linknum); | 165 | m_LSL_Functions.llBreakLink(linknum); |
165 | } | 166 | } |
166 | 167 | ||
168 | public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options) | ||
169 | { | ||
170 | return m_LSL_Functions.llCastRay(start, end, options); | ||
171 | } | ||
172 | |||
167 | public LSL_Integer llCeil(double f) | 173 | public LSL_Integer llCeil(double f) |
168 | { | 174 | { |
169 | return m_LSL_Functions.llCeil(f); | 175 | return m_LSL_Functions.llCeil(f); |
@@ -314,6 +320,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
314 | m_LSL_Functions.llDialog(avatar, message, buttons, chat_channel); | 320 | m_LSL_Functions.llDialog(avatar, message, buttons, chat_channel); |
315 | } | 321 | } |
316 | 322 | ||
323 | [DebuggerNonUserCode] | ||
317 | public void llDie() | 324 | public void llDie() |
318 | { | 325 | { |
319 | m_LSL_Functions.llDie(); | 326 | m_LSL_Functions.llDie(); |
@@ -464,6 +471,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
464 | return m_LSL_Functions.llGetFreeMemory(); | 471 | return m_LSL_Functions.llGetFreeMemory(); |
465 | } | 472 | } |
466 | 473 | ||
474 | public LSL_Integer llGetUsedMemory() | ||
475 | { | ||
476 | return m_LSL_Functions.llGetUsedMemory(); | ||
477 | } | ||
478 | |||
467 | public LSL_Integer llGetFreeURLs() | 479 | public LSL_Integer llGetFreeURLs() |
468 | { | 480 | { |
469 | return m_LSL_Functions.llGetFreeURLs(); | 481 | return m_LSL_Functions.llGetFreeURLs(); |
@@ -849,6 +861,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
849 | return m_LSL_Functions.llGiveMoney(destination, amount); | 861 | return m_LSL_Functions.llGiveMoney(destination, amount); |
850 | } | 862 | } |
851 | 863 | ||
864 | public LSL_String llTransferLindenDollars(string destination, int amount) | ||
865 | { | ||
866 | return m_LSL_Functions.llTransferLindenDollars(destination, amount); | ||
867 | } | ||
868 | |||
852 | public void llGodLikeRezObject(string inventory, LSL_Vector pos) | 869 | public void llGodLikeRezObject(string inventory, LSL_Vector pos) |
853 | { | 870 | { |
854 | m_LSL_Functions.llGodLikeRezObject(inventory, pos); | 871 | m_LSL_Functions.llGodLikeRezObject(inventory, pos); |
@@ -1563,6 +1580,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
1563 | m_LSL_Functions.llSetPos(pos); | 1580 | m_LSL_Functions.llSetPos(pos); |
1564 | } | 1581 | } |
1565 | 1582 | ||
1583 | public LSL_Integer llSetRegionPos(LSL_Vector pos) | ||
1584 | { | ||
1585 | return m_LSL_Functions.llSetRegionPos(pos); | ||
1586 | } | ||
1587 | |||
1566 | public void llSetPrimitiveParams(LSL_List rules) | 1588 | public void llSetPrimitiveParams(LSL_List rules) |
1567 | { | 1589 | { |
1568 | m_LSL_Functions.llSetPrimitiveParams(rules); | 1590 | m_LSL_Functions.llSetPrimitiveParams(rules); |
@@ -1798,6 +1820,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
1798 | m_LSL_Functions.llTargetRemove(number); | 1820 | m_LSL_Functions.llTargetRemove(number); |
1799 | } | 1821 | } |
1800 | 1822 | ||
1823 | public void llTeleportAgent(string agent, string simname, LSL_Vector pos, LSL_Vector lookAt) | ||
1824 | { | ||
1825 | m_LSL_Functions.llTeleportAgent(agent, simname, pos, lookAt); | ||
1826 | } | ||
1827 | |||
1801 | public void llTeleportAgentHome(string agent) | 1828 | public void llTeleportAgentHome(string agent) |
1802 | { | 1829 | { |
1803 | m_LSL_Functions.llTeleportAgentHome(agent); | 1830 | m_LSL_Functions.llTeleportAgentHome(agent); |
@@ -1913,9 +1940,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
1913 | return m_LSL_Functions.llClearLinkMedia(link, face); | 1940 | return m_LSL_Functions.llClearLinkMedia(link, face); |
1914 | } | 1941 | } |
1915 | 1942 | ||
1916 | public void print(string str) | 1943 | public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link) |
1944 | { | ||
1945 | return m_LSL_Functions.llGetLinkNumberOfSides(link); | ||
1946 | } | ||
1947 | |||
1948 | public void llSetKeyframedMotion(LSL_List frames, LSL_List options) | ||
1917 | { | 1949 | { |
1918 | m_LSL_Functions.print(str); | 1950 | m_LSL_Functions.llSetKeyframedMotion(frames, options); |
1919 | } | 1951 | } |
1920 | } | 1952 | } |
1921 | } | 1953 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs index 143b497..2e27f16 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs | |||
@@ -72,9 +72,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
72 | { | 72 | { |
73 | return m_LS_Functions.lsSetWindlightSceneTargeted(rules, target); | 73 | return m_LS_Functions.lsSetWindlightSceneTargeted(rules, target); |
74 | } | 74 | } |
75 | |||
75 | public void lsClearWindlightScene() | 76 | public void lsClearWindlightScene() |
76 | { | 77 | { |
77 | m_LS_Functions.lsClearWindlightScene(); | 78 | m_LS_Functions.lsClearWindlightScene(); |
78 | } | 79 | } |
80 | |||
81 | public LSL_List cmGetWindlightScene(LSL_List rules) | ||
82 | { | ||
83 | return m_LS_Functions.lsGetWindlightScene(rules); | ||
84 | } | ||
85 | |||
86 | public int cmSetWindlightScene(LSL_List rules) | ||
87 | { | ||
88 | return m_LS_Functions.lsSetWindlightScene(rules); | ||
89 | } | ||
90 | |||
91 | public int cmSetWindlightSceneTargeted(LSL_List rules, key target) | ||
92 | { | ||
93 | return m_LS_Functions.lsSetWindlightSceneTargeted(rules, target); | ||
94 | } | ||
95 | |||
96 | public void cmClearWindlightScene() | ||
97 | { | ||
98 | m_LS_Functions.lsClearWindlightScene(); | ||
99 | } | ||
79 | } | 100 | } |
80 | } | 101 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs index edbbc2a..b138da3 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs | |||
@@ -33,6 +33,7 @@ using System.Threading; | |||
33 | using System.Reflection; | 33 | using System.Reflection; |
34 | using System.Collections; | 34 | using System.Collections; |
35 | using System.Collections.Generic; | 35 | using System.Collections.Generic; |
36 | using System.Diagnostics; //for [DebuggerNonUserCode] | ||
36 | using OpenSim.Region.ScriptEngine.Interfaces; | 37 | using OpenSim.Region.ScriptEngine.Interfaces; |
37 | using OpenSim.Region.ScriptEngine.Shared; | 38 | using OpenSim.Region.ScriptEngine.Shared; |
38 | using OpenSim.Region.ScriptEngine.Shared.Api.Runtime; | 39 | using OpenSim.Region.ScriptEngine.Shared.Api.Runtime; |
@@ -90,6 +91,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
90 | return (int)m_Executor.GetStateEventFlags(state); | 91 | return (int)m_Executor.GetStateEventFlags(state); |
91 | } | 92 | } |
92 | 93 | ||
94 | [DebuggerNonUserCode] | ||
93 | public void ExecuteEvent(string state, string FunctionName, object[] args) | 95 | public void ExecuteEvent(string state, string FunctionName, object[] args) |
94 | { | 96 | { |
95 | m_Executor.ExecuteEvent(state, FunctionName, args); | 97 | m_Executor.ExecuteEvent(state, FunctionName, args); |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Helpers.cs b/OpenSim/Region/ScriptEngine/Shared/Helpers.cs index 8cebb4a..7e7e278 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Helpers.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Helpers.cs | |||
@@ -35,6 +35,7 @@ using OpenMetaverse; | |||
35 | using OpenSim.Framework; | 35 | using OpenSim.Framework; |
36 | using OpenSim.Region.CoreModules; | 36 | using OpenSim.Region.CoreModules; |
37 | using OpenSim.Region.Framework.Scenes; | 37 | using OpenSim.Region.Framework.Scenes; |
38 | using OpenSim.Services.Interfaces; | ||
38 | 39 | ||
39 | namespace OpenSim.Region.ScriptEngine.Shared | 40 | namespace OpenSim.Region.ScriptEngine.Shared |
40 | { | 41 | { |
@@ -95,6 +96,7 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
95 | Type = 0; | 96 | Type = 0; |
96 | Velocity = new LSL_Types.Vector3(); | 97 | Velocity = new LSL_Types.Vector3(); |
97 | initializeSurfaceTouch(); | 98 | initializeSurfaceTouch(); |
99 | Country = String.Empty; | ||
98 | } | 100 | } |
99 | 101 | ||
100 | public UUID Key; | 102 | public UUID Key; |
@@ -126,6 +128,8 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
126 | private int touchFace; | 128 | private int touchFace; |
127 | public int TouchFace { get { return touchFace; } } | 129 | public int TouchFace { get { return touchFace; } } |
128 | 130 | ||
131 | public string Country; | ||
132 | |||
129 | // This can be done in two places including the constructor | 133 | // This can be done in two places including the constructor |
130 | // so be carefull what gets added here | 134 | // so be carefull what gets added here |
131 | private void initializeSurfaceTouch() | 135 | private void initializeSurfaceTouch() |
@@ -173,6 +177,10 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
173 | return; | 177 | return; |
174 | 178 | ||
175 | Name = presence.Firstname + " " + presence.Lastname; | 179 | Name = presence.Firstname + " " + presence.Lastname; |
180 | UserAccount account = scene.UserAccountService.GetUserAccount(scene.RegionInfo.ScopeID, Key); | ||
181 | if (account != null) | ||
182 | Country = account.UserCountry; | ||
183 | |||
176 | Owner = Key; | 184 | Owner = Key; |
177 | Position = new LSL_Types.Vector3( | 185 | Position = new LSL_Types.Vector3( |
178 | presence.AbsolutePosition.X, | 186 | presence.AbsolutePosition.X, |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index bc1902b..da2ef7b 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | |||
@@ -27,6 +27,7 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.IO; | 29 | using System.IO; |
30 | using System.Diagnostics; //for [DebuggerNonUserCode] | ||
30 | using System.Runtime.Remoting; | 31 | using System.Runtime.Remoting; |
31 | using System.Runtime.Remoting.Lifetime; | 32 | using System.Runtime.Remoting.Lifetime; |
32 | using System.Threading; | 33 | using System.Threading; |
@@ -264,13 +265,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
264 | 265 | ||
265 | if (part != null) | 266 | if (part != null) |
266 | { | 267 | { |
267 | lock (part.TaskInventory) | 268 | part.TaskInventory.LockItemsForRead(true); |
269 | if (part.TaskInventory.ContainsKey(m_ItemID)) | ||
268 | { | 270 | { |
269 | if (part.TaskInventory.ContainsKey(m_ItemID)) | 271 | m_thisScriptTask = part.TaskInventory[m_ItemID]; |
270 | { | ||
271 | m_thisScriptTask = part.TaskInventory[m_ItemID]; | ||
272 | } | ||
273 | } | 272 | } |
273 | part.TaskInventory.LockItemsForRead(false); | ||
274 | } | 274 | } |
275 | 275 | ||
276 | ApiManager am = new ApiManager(); | 276 | ApiManager am = new ApiManager(); |
@@ -469,14 +469,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
469 | { | 469 | { |
470 | int permsMask; | 470 | int permsMask; |
471 | UUID permsGranter; | 471 | UUID permsGranter; |
472 | lock (part.TaskInventory) | 472 | part.TaskInventory.LockItemsForRead(true); |
473 | if (!part.TaskInventory.ContainsKey(m_ItemID)) | ||
473 | { | 474 | { |
474 | if (!part.TaskInventory.ContainsKey(m_ItemID)) | 475 | part.TaskInventory.LockItemsForRead(false); |
475 | return; | 476 | return; |
476 | |||
477 | permsGranter = part.TaskInventory[m_ItemID].PermsGranter; | ||
478 | permsMask = part.TaskInventory[m_ItemID].PermsMask; | ||
479 | } | 477 | } |
478 | permsGranter = part.TaskInventory[m_ItemID].PermsGranter; | ||
479 | permsMask = part.TaskInventory[m_ItemID].PermsMask; | ||
480 | part.TaskInventory.LockItemsForRead(false); | ||
480 | 481 | ||
481 | if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) | 482 | if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) |
482 | { | 483 | { |
@@ -588,6 +589,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
588 | return true; | 589 | return true; |
589 | } | 590 | } |
590 | 591 | ||
592 | [DebuggerNonUserCode] //Prevents the debugger from farting in this function | ||
591 | public void SetState(string state) | 593 | public void SetState(string state) |
592 | { | 594 | { |
593 | if (state == State) | 595 | if (state == State) |
@@ -599,7 +601,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
599 | new DetectParams[0])); | 601 | new DetectParams[0])); |
600 | PostEvent(new EventParams("state_entry", new Object[0], | 602 | PostEvent(new EventParams("state_entry", new Object[0], |
601 | new DetectParams[0])); | 603 | new DetectParams[0])); |
602 | 604 | ||
603 | throw new EventAbortException(); | 605 | throw new EventAbortException(); |
604 | } | 606 | } |
605 | 607 | ||
@@ -682,41 +684,42 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
682 | /// <returns></returns> | 684 | /// <returns></returns> |
683 | public object EventProcessor() | 685 | public object EventProcessor() |
684 | { | 686 | { |
685 | lock (m_Script) | 687 | EventParams data = null; |
686 | { | ||
687 | // m_log.DebugFormat("[XEngine]: EventProcessor() invoked for {0}.{1}", PrimName, ScriptName); | ||
688 | 688 | ||
689 | if (Suspended) | 689 | // m_log.DebugFormat("[XEngine]: EventProcessor() invoked for {0}.{1}", PrimName, ScriptName); |
690 | return 0; | ||
691 | 690 | ||
692 | EventParams data = null; | 691 | if (Suspended) |
692 | return 0; | ||
693 | 693 | ||
694 | lock (m_EventQueue) | 694 | lock (m_EventQueue) |
695 | { | ||
696 | data = (EventParams) m_EventQueue.Dequeue(); | ||
697 | if (data == null) // Shouldn't happen | ||
695 | { | 698 | { |
696 | data = (EventParams) m_EventQueue.Dequeue(); | 699 | if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown)) |
697 | if (data == null) // Shouldn't happen | ||
698 | { | 700 | { |
699 | if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown)) | 701 | m_CurrentResult = m_Engine.QueueEventHandler(this); |
700 | { | ||
701 | m_CurrentResult = m_Engine.QueueEventHandler(this); | ||
702 | } | ||
703 | else | ||
704 | { | ||
705 | m_CurrentResult = null; | ||
706 | } | ||
707 | return 0; | ||
708 | } | 702 | } |
709 | 703 | else | |
710 | if (data.EventName == "timer") | ||
711 | m_TimerQueued = false; | ||
712 | if (data.EventName == "control") | ||
713 | { | 704 | { |
714 | if (m_ControlEventsInQueue > 0) | 705 | m_CurrentResult = null; |
715 | m_ControlEventsInQueue--; | ||
716 | } | 706 | } |
717 | if (data.EventName == "collision") | 707 | return 0; |
718 | m_CollisionInQueue = false; | 708 | } |
709 | |||
710 | if (data.EventName == "timer") | ||
711 | m_TimerQueued = false; | ||
712 | if (data.EventName == "control") | ||
713 | { | ||
714 | if (m_ControlEventsInQueue > 0) | ||
715 | m_ControlEventsInQueue--; | ||
719 | } | 716 | } |
717 | if (data.EventName == "collision") | ||
718 | m_CollisionInQueue = false; | ||
719 | } | ||
720 | |||
721 | lock(m_Script) | ||
722 | { | ||
720 | 723 | ||
721 | // m_log.DebugFormat("[XEngine]: Processing event {0} for {1}", data.EventName, this); | 724 | // m_log.DebugFormat("[XEngine]: Processing event {0} for {1}", data.EventName, this); |
722 | 725 | ||
@@ -876,6 +879,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
876 | new Object[0], new DetectParams[0])); | 879 | new Object[0], new DetectParams[0])); |
877 | } | 880 | } |
878 | 881 | ||
882 | [DebuggerNonUserCode] //Stops the VS debugger from farting in this function | ||
879 | public void ApiResetScript() | 883 | public void ApiResetScript() |
880 | { | 884 | { |
881 | // bool running = Running; | 885 | // bool running = Running; |
@@ -907,10 +911,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
907 | 911 | ||
908 | public Dictionary<string, object> GetVars() | 912 | public Dictionary<string, object> GetVars() |
909 | { | 913 | { |
910 | if (m_Script != null) | 914 | return m_Script.GetVars(); |
911 | return m_Script.GetVars(); | ||
912 | else | ||
913 | return new Dictionary<string, object>(); | ||
914 | } | 915 | } |
915 | 916 | ||
916 | public void SetVars(Dictionary<string, object> vars) | 917 | public void SetVars(Dictionary<string, object> vars) |
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index d848b2a..8adf4c5 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs | |||
@@ -83,19 +83,19 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
83 | 83 | ||
84 | public override string ToString() | 84 | public override string ToString() |
85 | { | 85 | { |
86 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", x, y, z); | 86 | string s=String.Format("<{0:0.000000}, {1:0.000000}, {2:0.000000}>", x, y, z); |
87 | return s; | 87 | return s; |
88 | } | 88 | } |
89 | 89 | ||
90 | public static explicit operator LSLString(Vector3 vec) | 90 | public static explicit operator LSLString(Vector3 vec) |
91 | { | 91 | { |
92 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z); | 92 | string s=String.Format("<{0:0.000000}, {1:0.000000}, {2:0.000000}>", vec.x, vec.y, vec.z); |
93 | return new LSLString(s); | 93 | return new LSLString(s); |
94 | } | 94 | } |
95 | 95 | ||
96 | public static explicit operator string(Vector3 vec) | 96 | public static explicit operator string(Vector3 vec) |
97 | { | 97 | { |
98 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z); | 98 | string s=String.Format("<{0:0.000000}, {1:0.000000}, {2:0.000000}>", vec.x, vec.y, vec.z); |
99 | return s; | 99 | return s; |
100 | } | 100 | } |
101 | 101 | ||
@@ -342,19 +342,19 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
342 | 342 | ||
343 | public override string ToString() | 343 | public override string ToString() |
344 | { | 344 | { |
345 | string st=String.Format(Culture.FormatProvider, "<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", x, y, z, s); | 345 | string st=String.Format(Culture.FormatProvider, "<{0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000}>", x, y, z, s); |
346 | return st; | 346 | return st; |
347 | } | 347 | } |
348 | 348 | ||
349 | public static explicit operator string(Quaternion r) | 349 | public static explicit operator string(Quaternion r) |
350 | { | 350 | { |
351 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s); | 351 | string s=String.Format("<{0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000}>", r.x, r.y, r.z, r.s); |
352 | return s; | 352 | return s; |
353 | } | 353 | } |
354 | 354 | ||
355 | public static explicit operator LSLString(Quaternion r) | 355 | public static explicit operator LSLString(Quaternion r) |
356 | { | 356 | { |
357 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s); | 357 | string s=String.Format("<{0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000}>", r.x, r.y, r.z, r.s); |
358 | return new LSLString(s); | 358 | return new LSLString(s); |
359 | } | 359 | } |
360 | 360 | ||
@@ -459,6 +459,8 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
459 | size += 64; | 459 | size += 64; |
460 | else if (o is int) | 460 | else if (o is int) |
461 | size += 4; | 461 | size += 4; |
462 | else if (o is uint) | ||
463 | size += 4; | ||
462 | else if (o is string) | 464 | else if (o is string) |
463 | size += ((string)o).Length; | 465 | size += ((string)o).Length; |
464 | else if (o is float) | 466 | else if (o is float) |
@@ -613,24 +615,16 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
613 | 615 | ||
614 | public static bool operator ==(list a, list b) | 616 | public static bool operator ==(list a, list b) |
615 | { | 617 | { |
616 | int la = -1; | 618 | int la = a.Length; |
617 | int lb = -1; | 619 | int lb = b.Length; |
618 | try { la = a.Length; } | ||
619 | catch (NullReferenceException) { } | ||
620 | try { lb = b.Length; } | ||
621 | catch (NullReferenceException) { } | ||
622 | 620 | ||
623 | return la == lb; | 621 | return la == lb; |
624 | } | 622 | } |
625 | 623 | ||
626 | public static bool operator !=(list a, list b) | 624 | public static bool operator !=(list a, list b) |
627 | { | 625 | { |
628 | int la = -1; | 626 | int la = a.Length; |
629 | int lb = -1; | 627 | int lb = b.Length; |
630 | try { la = a.Length; } | ||
631 | catch (NullReferenceException) { } | ||
632 | try {lb = b.Length;} | ||
633 | catch (NullReferenceException) { } | ||
634 | 628 | ||
635 | return la != lb; | 629 | return la != lb; |
636 | } | 630 | } |
@@ -864,7 +858,7 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
864 | ret = Math.Sign(Quaternion.Mag(l) - Quaternion.Mag(r)); | 858 | ret = Math.Sign(Quaternion.Mag(l) - Quaternion.Mag(r)); |
865 | } | 859 | } |
866 | 860 | ||
867 | if (ascending == 0) | 861 | if (ascending != 1) |
868 | { | 862 | { |
869 | ret = 0 - ret; | 863 | ret = 0 - ret; |
870 | } | 864 | } |
@@ -897,6 +891,9 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
897 | stride = 1; | 891 | stride = 1; |
898 | } | 892 | } |
899 | 893 | ||
894 | if ((Data.Length % stride) != 0) | ||
895 | return new list(ret); | ||
896 | |||
900 | // we can optimize here in the case where stride == 1 and the list | 897 | // we can optimize here in the case where stride == 1 and the list |
901 | // consists of homogeneous types | 898 | // consists of homogeneous types |
902 | 899 | ||
@@ -916,7 +913,7 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
916 | if (homogeneous) | 913 | if (homogeneous) |
917 | { | 914 | { |
918 | Array.Sort(ret, new HomogeneousComparer()); | 915 | Array.Sort(ret, new HomogeneousComparer()); |
919 | if (ascending == 0) | 916 | if (ascending != 1) |
920 | { | 917 | { |
921 | Array.Reverse(ret); | 918 | Array.Reverse(ret); |
922 | } | 919 | } |
@@ -1064,7 +1061,7 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
1064 | { | 1061 | { |
1065 | list ret = new list(); | 1062 | list ret = new list(); |
1066 | double entry; | 1063 | double entry; |
1067 | for (int i = 0; i < src.Data.Length - 1; i++) | 1064 | for (int i = 0; i < src.Data.Length; i++) |
1068 | { | 1065 | { |
1069 | if (double.TryParse(src.Data[i].ToString(), NumberStyles.Float, Culture.NumberFormatInfo, out entry)) | 1066 | if (double.TryParse(src.Data[i].ToString(), NumberStyles.Float, Culture.NumberFormatInfo, out entry)) |
1070 | { | 1067 | { |
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index b433430..db6a407 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | |||
@@ -28,6 +28,7 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Diagnostics; //for [DebuggerNonUserCode] | ||
31 | using System.Globalization; | 32 | using System.Globalization; |
32 | using System.IO; | 33 | using System.IO; |
33 | using System.Reflection; | 34 | using System.Reflection; |
@@ -112,6 +113,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
112 | private Dictionary<UUID, IScriptInstance> m_Scripts = | 113 | private Dictionary<UUID, IScriptInstance> m_Scripts = |
113 | new Dictionary<UUID, IScriptInstance>(); | 114 | new Dictionary<UUID, IScriptInstance>(); |
114 | 115 | ||
116 | private OpenMetaverse.ReaderWriterLockSlim m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim(); | ||
117 | |||
115 | // Maps the asset ID to the assembly | 118 | // Maps the asset ID to the assembly |
116 | 119 | ||
117 | private Dictionary<UUID, string> m_Assemblies = | 120 | private Dictionary<UUID, string> m_Assemblies = |
@@ -134,6 +137,71 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
134 | IWorkItemResult m_CurrentCompile = null; | 137 | IWorkItemResult m_CurrentCompile = null; |
135 | private Dictionary<UUID, int> m_CompileDict = new Dictionary<UUID, int>(); | 138 | private Dictionary<UUID, int> m_CompileDict = new Dictionary<UUID, int>(); |
136 | 139 | ||
140 | private void lockScriptsForRead(bool locked) | ||
141 | { | ||
142 | if (locked) | ||
143 | { | ||
144 | if (m_scriptsLock.RecursiveReadCount > 0) | ||
145 | { | ||
146 | m_log.Error("[XEngine.m_Scripts] Recursive read lock requested. This should not happen and means something needs to be fixed. For now though, it's safe to continue."); | ||
147 | m_scriptsLock.ExitReadLock(); | ||
148 | } | ||
149 | if (m_scriptsLock.RecursiveWriteCount > 0) | ||
150 | { | ||
151 | m_log.Error("[XEngine.m_Scripts] Recursive write lock requested. This should not happen and means something needs to be fixed."); | ||
152 | m_scriptsLock.ExitWriteLock(); | ||
153 | } | ||
154 | |||
155 | while (!m_scriptsLock.TryEnterReadLock(60000)) | ||
156 | { | ||
157 | m_log.Error("[XEngine.m_Scripts] Thread lock detected while trying to aquire READ lock of m_scripts in XEngine. I'm going to try to solve the thread lock automatically to preserve region stability, but this needs to be fixed."); | ||
158 | if (m_scriptsLock.IsWriteLockHeld) | ||
159 | { | ||
160 | m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim(); | ||
161 | } | ||
162 | } | ||
163 | } | ||
164 | else | ||
165 | { | ||
166 | if (m_scriptsLock.RecursiveReadCount > 0) | ||
167 | { | ||
168 | m_scriptsLock.ExitReadLock(); | ||
169 | } | ||
170 | } | ||
171 | } | ||
172 | private void lockScriptsForWrite(bool locked) | ||
173 | { | ||
174 | if (locked) | ||
175 | { | ||
176 | if (m_scriptsLock.RecursiveReadCount > 0) | ||
177 | { | ||
178 | m_log.Error("[XEngine.m_Scripts] Recursive read lock requested. This should not happen and means something needs to be fixed. For now though, it's safe to continue."); | ||
179 | m_scriptsLock.ExitReadLock(); | ||
180 | } | ||
181 | if (m_scriptsLock.RecursiveWriteCount > 0) | ||
182 | { | ||
183 | m_log.Error("[XEngine.m_Scripts] Recursive write lock requested. This should not happen and means something needs to be fixed."); | ||
184 | m_scriptsLock.ExitWriteLock(); | ||
185 | } | ||
186 | |||
187 | while (!m_scriptsLock.TryEnterWriteLock(60000)) | ||
188 | { | ||
189 | m_log.Error("[XEngine.m_Scripts] Thread lock detected while trying to aquire WRITE lock of m_scripts in XEngine. I'm going to try to solve the thread lock automatically to preserve region stability, but this needs to be fixed."); | ||
190 | if (m_scriptsLock.IsWriteLockHeld) | ||
191 | { | ||
192 | m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim(); | ||
193 | } | ||
194 | } | ||
195 | } | ||
196 | else | ||
197 | { | ||
198 | if (m_scriptsLock.RecursiveWriteCount > 0) | ||
199 | { | ||
200 | m_scriptsLock.ExitWriteLock(); | ||
201 | } | ||
202 | } | ||
203 | } | ||
204 | |||
137 | public string ScriptEngineName | 205 | public string ScriptEngineName |
138 | { | 206 | { |
139 | get { return "XEngine"; } | 207 | get { return "XEngine"; } |
@@ -516,44 +584,37 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
516 | { | 584 | { |
517 | if (!m_Enabled) | 585 | if (!m_Enabled) |
518 | return; | 586 | return; |
519 | 587 | lockScriptsForRead(true); | |
520 | lock (m_Scripts) | 588 | foreach (IScriptInstance instance in m_Scripts.Values) |
521 | { | 589 | { |
522 | m_log.InfoFormat( | 590 | // Force a final state save |
523 | "[XEngine]: Shutting down {0} scripts in {1}", m_Scripts.Count, m_Scene.RegionInfo.RegionName); | 591 | // |
524 | 592 | if (m_Assemblies.ContainsKey(instance.AssetID)) | |
525 | foreach (IScriptInstance instance in m_Scripts.Values) | ||
526 | { | 593 | { |
527 | // Force a final state save | 594 | string assembly = m_Assemblies[instance.AssetID]; |
528 | // | 595 | instance.SaveState(assembly); |
529 | if (m_Assemblies.ContainsKey(instance.AssetID)) | 596 | } |
530 | { | ||
531 | string assembly = m_Assemblies[instance.AssetID]; | ||
532 | instance.SaveState(assembly); | ||
533 | } | ||
534 | 597 | ||
535 | // Clear the event queue and abort the instance thread | 598 | // Clear the event queue and abort the instance thread |
536 | // | 599 | // |
537 | instance.ClearQueue(); | 600 | instance.ClearQueue(); |
538 | instance.Stop(0); | 601 | instance.Stop(0); |
539 | 602 | ||
540 | // Release events, timer, etc | 603 | // Release events, timer, etc |
541 | // | 604 | // |
542 | instance.DestroyScriptInstance(); | 605 | instance.DestroyScriptInstance(); |
543 | 606 | ||
544 | // Unload scripts and app domains. | 607 | // Unload scripts and app domains |
545 | // Must be done explicitly because they have infinite | 608 | // Must be done explicitly because they have infinite |
546 | // lifetime. | 609 | // lifetime |
547 | // However, don't bother to do this if the simulator is shutting | 610 | // |
548 | // down since it takes a long time with many scripts. | 611 | if (!m_SimulatorShuttingDown) |
549 | if (!m_SimulatorShuttingDown) | 612 | { |
613 | m_DomainScripts[instance.AppDomain].Remove(instance.ItemID); | ||
614 | if (m_DomainScripts[instance.AppDomain].Count == 0) | ||
550 | { | 615 | { |
551 | m_DomainScripts[instance.AppDomain].Remove(instance.ItemID); | 616 | m_DomainScripts.Remove(instance.AppDomain); |
552 | if (m_DomainScripts[instance.AppDomain].Count == 0) | 617 | UnloadAppDomain(instance.AppDomain); |
553 | { | ||
554 | m_DomainScripts.Remove(instance.AppDomain); | ||
555 | UnloadAppDomain(instance.AppDomain); | ||
556 | } | ||
557 | } | 618 | } |
558 | } | 619 | } |
559 | 620 | ||
@@ -562,6 +623,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
562 | m_Assemblies.Clear(); | 623 | m_Assemblies.Clear(); |
563 | m_DomainScripts.Clear(); | 624 | m_DomainScripts.Clear(); |
564 | } | 625 | } |
626 | lockScriptsForRead(false); | ||
627 | lockScriptsForWrite(true); | ||
628 | m_Scripts.Clear(); | ||
629 | lockScriptsForWrite(false); | ||
630 | m_PrimObjects.Clear(); | ||
631 | m_Assemblies.Clear(); | ||
632 | m_DomainScripts.Clear(); | ||
633 | |||
565 | lock (m_ScriptEngines) | 634 | lock (m_ScriptEngines) |
566 | { | 635 | { |
567 | m_ScriptEngines.Remove(this); | 636 | m_ScriptEngines.Remove(this); |
@@ -626,22 +695,20 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
626 | 695 | ||
627 | List<IScriptInstance> instances = new List<IScriptInstance>(); | 696 | List<IScriptInstance> instances = new List<IScriptInstance>(); |
628 | 697 | ||
629 | lock (m_Scripts) | 698 | lockScriptsForRead(true); |
630 | { | 699 | foreach (IScriptInstance instance in m_Scripts.Values) |
631 | foreach (IScriptInstance instance in m_Scripts.Values) | ||
632 | instances.Add(instance); | 700 | instances.Add(instance); |
633 | } | 701 | lockScriptsForRead(false); |
634 | 702 | ||
635 | foreach (IScriptInstance i in instances) | 703 | foreach (IScriptInstance i in instances) |
636 | { | 704 | { |
637 | string assembly = String.Empty; | 705 | string assembly = String.Empty; |
638 | 706 | ||
639 | lock (m_Scripts) | 707 | |
640 | { | ||
641 | if (!m_Assemblies.ContainsKey(i.AssetID)) | 708 | if (!m_Assemblies.ContainsKey(i.AssetID)) |
642 | continue; | 709 | continue; |
643 | assembly = m_Assemblies[i.AssetID]; | 710 | assembly = m_Assemblies[i.AssetID]; |
644 | } | 711 | |
645 | 712 | ||
646 | i.SaveState(assembly); | 713 | i.SaveState(assembly); |
647 | } | 714 | } |
@@ -985,92 +1052,95 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
985 | } | 1052 | } |
986 | 1053 | ||
987 | ScriptInstance instance = null; | 1054 | ScriptInstance instance = null; |
988 | lock (m_Scripts) | 1055 | // Create the object record |
1056 | lockScriptsForRead(true); | ||
1057 | if ((!m_Scripts.ContainsKey(itemID)) || | ||
1058 | (m_Scripts[itemID].AssetID != assetID)) | ||
989 | { | 1059 | { |
990 | // Create the object record | 1060 | lockScriptsForRead(false); |
991 | 1061 | ||
992 | if ((!m_Scripts.ContainsKey(itemID)) || | 1062 | UUID appDomain = assetID; |
993 | (m_Scripts[itemID].AssetID != assetID)) | ||
994 | { | ||
995 | UUID appDomain = assetID; | ||
996 | 1063 | ||
997 | if (part.ParentGroup.IsAttachment) | 1064 | if (part.ParentGroup.IsAttachment) |
998 | appDomain = part.ParentGroup.RootPart.UUID; | 1065 | appDomain = part.ParentGroup.RootPart.UUID; |
999 | 1066 | ||
1000 | if (!m_AppDomains.ContainsKey(appDomain)) | 1067 | if (!m_AppDomains.ContainsKey(appDomain)) |
1068 | { | ||
1069 | try | ||
1001 | { | 1070 | { |
1002 | try | 1071 | AppDomainSetup appSetup = new AppDomainSetup(); |
1003 | { | 1072 | appSetup.PrivateBinPath = Path.Combine( |
1004 | AppDomainSetup appSetup = new AppDomainSetup(); | 1073 | m_ScriptEnginesPath, |
1005 | appSetup.PrivateBinPath = Path.Combine( | 1074 | m_Scene.RegionInfo.RegionID.ToString()); |
1006 | m_ScriptEnginesPath, | 1075 | |
1007 | m_Scene.RegionInfo.RegionID.ToString()); | 1076 | Evidence baseEvidence = AppDomain.CurrentDomain.Evidence; |
1008 | 1077 | Evidence evidence = new Evidence(baseEvidence); | |
1009 | Evidence baseEvidence = AppDomain.CurrentDomain.Evidence; | 1078 | |
1010 | Evidence evidence = new Evidence(baseEvidence); | 1079 | AppDomain sandbox; |
1011 | 1080 | if (m_AppDomainLoading) | |
1012 | AppDomain sandbox; | 1081 | sandbox = AppDomain.CreateDomain( |
1013 | if (m_AppDomainLoading) | 1082 | m_Scene.RegionInfo.RegionID.ToString(), |
1014 | sandbox = AppDomain.CreateDomain( | 1083 | evidence, appSetup); |
1015 | m_Scene.RegionInfo.RegionID.ToString(), | 1084 | else |
1016 | evidence, appSetup); | 1085 | sandbox = AppDomain.CurrentDomain; |
1017 | else | 1086 | |
1018 | sandbox = AppDomain.CurrentDomain; | 1087 | //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel(); |
1019 | 1088 | //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition(); | |
1020 | //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel(); | 1089 | //PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet"); |
1021 | //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition(); | 1090 | //PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet); |
1022 | //PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet"); | 1091 | //CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement); |
1023 | //PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet); | 1092 | //sandboxPolicy.RootCodeGroup = sandboxCodeGroup; |
1024 | //CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement); | 1093 | //sandbox.SetAppDomainPolicy(sandboxPolicy); |
1025 | //sandboxPolicy.RootCodeGroup = sandboxCodeGroup; | 1094 | |
1026 | //sandbox.SetAppDomainPolicy(sandboxPolicy); | 1095 | m_AppDomains[appDomain] = sandbox; |
1027 | 1096 | ||
1028 | m_AppDomains[appDomain] = sandbox; | 1097 | m_AppDomains[appDomain].AssemblyResolve += |
1029 | 1098 | new ResolveEventHandler( | |
1030 | m_AppDomains[appDomain].AssemblyResolve += | 1099 | AssemblyResolver.OnAssemblyResolve); |
1031 | new ResolveEventHandler( | 1100 | m_DomainScripts[appDomain] = new List<UUID>(); |
1032 | AssemblyResolver.OnAssemblyResolve); | 1101 | } |
1033 | m_DomainScripts[appDomain] = new List<UUID>(); | 1102 | catch (Exception e) |
1034 | } | 1103 | { |
1035 | catch (Exception e) | 1104 | m_log.ErrorFormat("[XEngine] Exception creating app domain:\n {0}", e.ToString()); |
1105 | m_ScriptErrorMessage += "Exception creating app domain:\n"; | ||
1106 | m_ScriptFailCount++; | ||
1107 | lock (m_AddingAssemblies) | ||
1036 | { | 1108 | { |
1037 | m_log.ErrorFormat("[XEngine] Exception creating app domain:\n {0}", e.ToString()); | 1109 | m_AddingAssemblies[assembly]--; |
1038 | m_ScriptErrorMessage += "Exception creating app domain:\n"; | ||
1039 | m_ScriptFailCount++; | ||
1040 | lock (m_AddingAssemblies) | ||
1041 | { | ||
1042 | m_AddingAssemblies[assembly]--; | ||
1043 | } | ||
1044 | return false; | ||
1045 | } | 1110 | } |
1111 | return false; | ||
1046 | } | 1112 | } |
1047 | m_DomainScripts[appDomain].Add(itemID); | 1113 | } |
1048 | 1114 | m_DomainScripts[appDomain].Add(itemID); | |
1049 | instance = new ScriptInstance(this, part, | 1115 | |
1050 | itemID, assetID, assembly, | 1116 | instance = new ScriptInstance(this, part, |
1051 | m_AppDomains[appDomain], | 1117 | itemID, assetID, assembly, |
1052 | part.ParentGroup.RootPart.Name, | 1118 | m_AppDomains[appDomain], |
1053 | item.Name, startParam, postOnRez, | 1119 | part.ParentGroup.RootPart.Name, |
1054 | stateSource, m_MaxScriptQueue); | 1120 | item.Name, startParam, postOnRez, |
1055 | 1121 | stateSource, m_MaxScriptQueue); | |
1056 | m_log.DebugFormat( | 1122 | |
1057 | "[XEngine] Loaded script {0}.{1}, item UUID {2}, prim UUID {3} @ {4}.{5}", | 1123 | m_log.DebugFormat( |
1058 | part.ParentGroup.RootPart.Name, item.Name, itemID, part.UUID, | 1124 | "[XEngine] Loaded script {0}.{1}, script UUID {2}, prim UUID {3} @ {4}.{5}", |
1125 | part.ParentGroup.RootPart.Name, item.Name, assetID, part.UUID, | ||
1059 | part.ParentGroup.RootPart.AbsolutePosition, part.ParentGroup.Scene.RegionInfo.RegionName); | 1126 | part.ParentGroup.RootPart.AbsolutePosition, part.ParentGroup.Scene.RegionInfo.RegionName); |
1060 | 1127 | ||
1061 | if (presence != null) | 1128 | if (presence != null) |
1062 | { | 1129 | { |
1063 | ShowScriptSaveResponse(item.OwnerID, | 1130 | ShowScriptSaveResponse(item.OwnerID, |
1064 | assetID, "Compile successful", true); | 1131 | assetID, "Compile successful", true); |
1065 | } | ||
1066 | |||
1067 | instance.AppDomain = appDomain; | ||
1068 | instance.LineMap = linemap; | ||
1069 | |||
1070 | m_Scripts[itemID] = instance; | ||
1071 | } | 1132 | } |
1072 | } | ||
1073 | 1133 | ||
1134 | instance.AppDomain = appDomain; | ||
1135 | instance.LineMap = linemap; | ||
1136 | lockScriptsForWrite(true); | ||
1137 | m_Scripts[itemID] = instance; | ||
1138 | lockScriptsForWrite(false); | ||
1139 | } | ||
1140 | else | ||
1141 | { | ||
1142 | lockScriptsForRead(false); | ||
1143 | } | ||
1074 | lock (m_PrimObjects) | 1144 | lock (m_PrimObjects) |
1075 | { | 1145 | { |
1076 | if (!m_PrimObjects.ContainsKey(localID)) | 1146 | if (!m_PrimObjects.ContainsKey(localID)) |
@@ -1089,9 +1159,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1089 | m_AddingAssemblies[assembly]--; | 1159 | m_AddingAssemblies[assembly]--; |
1090 | } | 1160 | } |
1091 | 1161 | ||
1092 | if (instance != null) | 1162 | if (instance!=null) |
1093 | instance.Init(); | 1163 | instance.Init(); |
1094 | 1164 | ||
1095 | return true; | 1165 | return true; |
1096 | } | 1166 | } |
1097 | 1167 | ||
@@ -1104,20 +1174,31 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1104 | m_CompileDict.Remove(itemID); | 1174 | m_CompileDict.Remove(itemID); |
1105 | } | 1175 | } |
1106 | 1176 | ||
1107 | IScriptInstance instance = null; | 1177 | lockScriptsForRead(true); |
1108 | 1178 | // Do we even have it? | |
1109 | lock (m_Scripts) | 1179 | if (!m_Scripts.ContainsKey(itemID)) |
1110 | { | 1180 | { |
1111 | // Do we even have it? | 1181 | // Do we even have it? |
1112 | if (!m_Scripts.ContainsKey(itemID)) | 1182 | if (!m_Scripts.ContainsKey(itemID)) |
1113 | return; | 1183 | return; |
1114 | 1184 | ||
1115 | instance = m_Scripts[itemID]; | 1185 | lockScriptsForRead(false); |
1186 | lockScriptsForWrite(true); | ||
1116 | m_Scripts.Remove(itemID); | 1187 | m_Scripts.Remove(itemID); |
1188 | lockScriptsForWrite(false); | ||
1189 | |||
1190 | return; | ||
1117 | } | 1191 | } |
1192 | |||
1118 | 1193 | ||
1194 | IScriptInstance instance=m_Scripts[itemID]; | ||
1195 | lockScriptsForRead(false); | ||
1196 | lockScriptsForWrite(true); | ||
1197 | m_Scripts.Remove(itemID); | ||
1198 | lockScriptsForWrite(false); | ||
1119 | instance.ClearQueue(); | 1199 | instance.ClearQueue(); |
1120 | instance.Stop(0); | 1200 | instance.Stop(0); |
1201 | |||
1121 | // bool objectRemoved = false; | 1202 | // bool objectRemoved = false; |
1122 | 1203 | ||
1123 | lock (m_PrimObjects) | 1204 | lock (m_PrimObjects) |
@@ -1153,10 +1234,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1153 | ObjectRemoved handlerObjectRemoved = OnObjectRemoved; | 1234 | ObjectRemoved handlerObjectRemoved = OnObjectRemoved; |
1154 | if (handlerObjectRemoved != null) | 1235 | if (handlerObjectRemoved != null) |
1155 | { | 1236 | { |
1156 | SceneObjectPart part = m_Scene.GetSceneObjectPart(localID); | 1237 | SceneObjectPart part = m_Scene.GetSceneObjectPart(localID); |
1157 | handlerObjectRemoved(part.UUID); | 1238 | handlerObjectRemoved(part.UUID); |
1158 | } | 1239 | } |
1159 | 1240 | ||
1241 | CleanAssemblies(); | ||
1242 | |||
1160 | ScriptRemoved handlerScriptRemoved = OnScriptRemoved; | 1243 | ScriptRemoved handlerScriptRemoved = OnScriptRemoved; |
1161 | if (handlerScriptRemoved != null) | 1244 | if (handlerScriptRemoved != null) |
1162 | handlerScriptRemoved(itemID); | 1245 | handlerScriptRemoved(itemID); |
@@ -1298,7 +1381,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1298 | return false; | 1381 | return false; |
1299 | 1382 | ||
1300 | uuids = m_PrimObjects[localID]; | 1383 | uuids = m_PrimObjects[localID]; |
1301 | } | 1384 | |
1302 | 1385 | ||
1303 | foreach (UUID itemID in uuids) | 1386 | foreach (UUID itemID in uuids) |
1304 | { | 1387 | { |
@@ -1316,6 +1399,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1316 | result = true; | 1399 | result = true; |
1317 | } | 1400 | } |
1318 | } | 1401 | } |
1402 | } | ||
1319 | 1403 | ||
1320 | return result; | 1404 | return result; |
1321 | } | 1405 | } |
@@ -1417,12 +1501,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1417 | private IScriptInstance GetInstance(UUID itemID) | 1501 | private IScriptInstance GetInstance(UUID itemID) |
1418 | { | 1502 | { |
1419 | IScriptInstance instance; | 1503 | IScriptInstance instance; |
1420 | lock (m_Scripts) | 1504 | lockScriptsForRead(true); |
1505 | if (!m_Scripts.ContainsKey(itemID)) | ||
1421 | { | 1506 | { |
1422 | if (!m_Scripts.ContainsKey(itemID)) | 1507 | lockScriptsForRead(false); |
1423 | return null; | 1508 | return null; |
1424 | instance = m_Scripts[itemID]; | ||
1425 | } | 1509 | } |
1510 | instance = m_Scripts[itemID]; | ||
1511 | lockScriptsForRead(false); | ||
1426 | return instance; | 1512 | return instance; |
1427 | } | 1513 | } |
1428 | 1514 | ||
@@ -1446,6 +1532,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1446 | return false; | 1532 | return false; |
1447 | } | 1533 | } |
1448 | 1534 | ||
1535 | [DebuggerNonUserCode] | ||
1449 | public void ApiResetScript(UUID itemID) | 1536 | public void ApiResetScript(UUID itemID) |
1450 | { | 1537 | { |
1451 | IScriptInstance instance = GetInstance(itemID); | 1538 | IScriptInstance instance = GetInstance(itemID); |
@@ -1497,6 +1584,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1497 | return UUID.Zero; | 1584 | return UUID.Zero; |
1498 | } | 1585 | } |
1499 | 1586 | ||
1587 | [DebuggerNonUserCode] | ||
1500 | public void SetState(UUID itemID, string newState) | 1588 | public void SetState(UUID itemID, string newState) |
1501 | { | 1589 | { |
1502 | IScriptInstance instance = GetInstance(itemID); | 1590 | IScriptInstance instance = GetInstance(itemID); |
@@ -1519,11 +1607,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1519 | 1607 | ||
1520 | List<IScriptInstance> instances = new List<IScriptInstance>(); | 1608 | List<IScriptInstance> instances = new List<IScriptInstance>(); |
1521 | 1609 | ||
1522 | lock (m_Scripts) | 1610 | lockScriptsForRead(true); |
1523 | { | 1611 | foreach (IScriptInstance instance in m_Scripts.Values) |
1524 | foreach (IScriptInstance instance in m_Scripts.Values) | ||
1525 | instances.Add(instance); | 1612 | instances.Add(instance); |
1526 | } | 1613 | lockScriptsForRead(false); |
1527 | 1614 | ||
1528 | foreach (IScriptInstance i in instances) | 1615 | foreach (IScriptInstance i in instances) |
1529 | { | 1616 | { |
@@ -1908,5 +1995,17 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1908 | // else | 1995 | // else |
1909 | // m_log.DebugFormat("[XEngine]: Could not find script with ID {0} to resume", itemID); | 1996 | // m_log.DebugFormat("[XEngine]: Could not find script with ID {0} to resume", itemID); |
1910 | } | 1997 | } |
1998 | |||
1999 | public bool HasScript(UUID itemID, out bool running) | ||
2000 | { | ||
2001 | running = true; | ||
2002 | |||
2003 | IScriptInstance instance = GetInstance(itemID); | ||
2004 | if (instance == null) | ||
2005 | return false; | ||
2006 | |||
2007 | running = instance.Running; | ||
2008 | return true; | ||
2009 | } | ||
1911 | } | 2010 | } |
1912 | } \ No newline at end of file | 2011 | } |