aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs122
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs104
2 files changed, 137 insertions, 89 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs b/OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs
new file mode 100644
index 0000000..d8aa258
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs
@@ -0,0 +1,122 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using OpenMetaverse;
31using OpenSim.Framework;
32
33namespace OpenSim.Region.Framework.Scenes.Scripting
34{
35 /// <summary>
36 /// Utility functions for use by scripts manipulating the scene.
37 /// </summary>
38 public static class ScriptUtils
39 {
40 /// <summary>
41 /// Get an asset id given an item name and an item type.
42 /// </summary>
43 /// <returns>UUID.Zero if the name and type did not match any item.</returns>
44 /// <param name='part'></param>
45 /// <param name='name'></param>
46 /// <param name='type'></param>
47 public static UUID GetAssetIdFromItemName(SceneObjectPart part, string name, int type)
48 {
49 TaskInventoryItem item = part.Inventory.GetInventoryItem(name);
50
51 if (item != null && item.Type == type)
52 return item.AssetID;
53 else
54 return UUID.Zero;
55 }
56
57 /// <summary>
58 /// accepts a valid UUID, -or- a name of an inventory item.
59 /// Returns a valid UUID or UUID.Zero if key invalid and item not found
60 /// in prim inventory.
61 /// </summary>
62 /// <param name="part">Scene object part to search for inventory item</param>
63 /// <param name="key"></param>
64 /// <returns></returns>
65 public static UUID GetAssetIdFromKeyOrItemName(SceneObjectPart part, string identifier)
66 {
67 UUID key;
68
69 // if we can parse the string as a key, use it.
70 // else try to locate the name in inventory of object. found returns key,
71 // not found returns UUID.Zero
72 if (!UUID.TryParse(identifier, out key))
73 {
74 TaskInventoryItem item = part.Inventory.GetInventoryItem(identifier);
75
76 if (item != null)
77 key = item.AssetID;
78 else
79 key = UUID.Zero;
80 }
81
82 return key;
83 }
84
85
86 /// <summary>
87 /// Return the UUID of the asset matching the specified key or name
88 /// and asset type.
89 /// </summary>
90 /// <param name="part">Scene object part to search for inventory item</param>
91 /// <param name="identifier"></param>
92 /// <param name="type"></param>
93 /// <returns></returns>
94 public static UUID GetAssetIdFromKeyOrItemName(SceneObjectPart part, string identifier, AssetType type)
95 {
96 UUID key;
97
98 if (!UUID.TryParse(identifier, out key))
99 {
100 TaskInventoryItem item = part.Inventory.GetInventoryItem(identifier);
101 if (item != null && item.Type == (int)type)
102 key = item.AssetID;
103 }
104 else
105 {
106 lock (part.TaskInventory)
107 {
108 foreach (KeyValuePair<UUID, TaskInventoryItem> item in part.TaskInventory)
109 {
110 if (item.Value.Type == (int)type && item.Value.Name == identifier)
111 {
112 key = item.Value.ItemID;
113 break;
114 }
115 }
116 }
117 }
118
119 return key;
120 }
121 }
122} \ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 0db6fe3..4fa3c60 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -45,6 +45,7 @@ using OpenSim.Region.CoreModules.World.Terrain;
45using OpenSim.Region.Framework.Interfaces; 45using OpenSim.Region.Framework.Interfaces;
46using OpenSim.Region.Framework.Scenes; 46using OpenSim.Region.Framework.Scenes;
47using OpenSim.Region.Framework.Scenes.Animation; 47using OpenSim.Region.Framework.Scenes.Animation;
48using OpenSim.Region.Framework.Scenes.Scripting;
48using OpenSim.Region.Physics.Manager; 49using OpenSim.Region.Physics.Manager;
49using OpenSim.Region.ScriptEngine.Shared; 50using OpenSim.Region.ScriptEngine.Shared;
50using OpenSim.Region.ScriptEngine.Shared.Api.Plugins; 51using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
@@ -333,79 +334,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
333 } 334 }
334 } 335 }
335 336
336 protected UUID InventoryKey(string name, int type)
337 {
338 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
339
340 if (item != null && item.Type == type)
341 return item.AssetID;
342 else
343 return UUID.Zero;
344 }
345
346 /// <summary>
347 /// accepts a valid UUID, -or- a name of an inventory item.
348 /// Returns a valid UUID or UUID.Zero if key invalid and item not found
349 /// in prim inventory.
350 /// </summary>
351 /// <param name="k"></param>
352 /// <returns></returns>
353 protected UUID KeyOrName(string k)
354 {
355 UUID key;
356
357 // if we can parse the string as a key, use it.
358 // else try to locate the name in inventory of object. found returns key,
359 // not found returns UUID.Zero
360 if (!UUID.TryParse(k, out key))
361 {
362 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(k);
363
364 if (item != null)
365 key = item.AssetID;
366 else
367 key = UUID.Zero;
368 }
369
370 return key;
371 }
372
373 /// <summary>
374 /// Return the UUID of the asset matching the specified key or name
375 /// and asset type.
376 /// </summary>
377 /// <param name="k"></param>
378 /// <param name="type"></param>
379 /// <returns></returns>
380 protected UUID KeyOrName(string k, AssetType type)
381 {
382 UUID key;
383
384 if (!UUID.TryParse(k, out key))
385 {
386 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(k);
387 if (item != null && item.Type == (int)type)
388 key = item.AssetID;
389 }
390 else
391 {
392 lock (m_host.TaskInventory)
393 {
394 foreach (KeyValuePair<UUID, TaskInventoryItem> item in m_host.TaskInventory)
395 {
396 if (item.Value.Type == (int)type && item.Value.Name == k)
397 {
398 key = item.Value.ItemID;
399 break;
400 }
401 }
402 }
403 }
404
405
406 return key;
407 }
408
409 //These are the implementations of the various ll-functions used by the LSL scripts. 337 //These are the implementations of the various ll-functions used by the LSL scripts.
410 public LSL_Float llSin(double f) 338 public LSL_Float llSin(double f)
411 { 339 {
@@ -1816,7 +1744,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1816 { 1744 {
1817 UUID textureID = new UUID(); 1745 UUID textureID = new UUID();
1818 1746
1819 textureID = InventoryKey(texture, (int)AssetType.Texture); 1747 textureID = ScriptUtils.GetAssetIdFromItemName(m_host, texture, (int)AssetType.Texture);
1820 if (textureID == UUID.Zero) 1748 if (textureID == UUID.Zero)
1821 { 1749 {
1822 if (!UUID.TryParse(texture, out textureID)) 1750 if (!UUID.TryParse(texture, out textureID))
@@ -2450,7 +2378,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2450 if (m_SoundModule != null) 2378 if (m_SoundModule != null)
2451 { 2379 {
2452 m_SoundModule.SendSound(m_host.UUID, 2380 m_SoundModule.SendSound(m_host.UUID,
2453 KeyOrName(sound, AssetType.Sound), volume, false, 0, 2381 ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume, false, 0,
2454 0, false, false); 2382 0, false, false);
2455 } 2383 }
2456 } 2384 }
@@ -2460,7 +2388,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2460 m_host.AddScriptLPS(1); 2388 m_host.AddScriptLPS(1);
2461 if (m_SoundModule != null) 2389 if (m_SoundModule != null)
2462 { 2390 {
2463 m_SoundModule.LoopSound(m_host.UUID, KeyOrName(sound), 2391 m_SoundModule.LoopSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound),
2464 volume, 20, false); 2392 volume, 20, false);
2465 } 2393 }
2466 } 2394 }
@@ -2470,7 +2398,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2470 m_host.AddScriptLPS(1); 2398 m_host.AddScriptLPS(1);
2471 if (m_SoundModule != null) 2399 if (m_SoundModule != null)
2472 { 2400 {
2473 m_SoundModule.LoopSound(m_host.UUID, KeyOrName(sound), 2401 m_SoundModule.LoopSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound),
2474 volume, 20, true); 2402 volume, 20, true);
2475 } 2403 }
2476 } 2404 }
@@ -2492,7 +2420,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2492 if (m_SoundModule != null) 2420 if (m_SoundModule != null)
2493 { 2421 {
2494 m_SoundModule.SendSound(m_host.UUID, 2422 m_SoundModule.SendSound(m_host.UUID,
2495 KeyOrName(sound, AssetType.Sound), volume, false, 0, 2423 ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume, false, 0,
2496 0, true, false); 2424 0, true, false);
2497 } 2425 }
2498 } 2426 }
@@ -2504,7 +2432,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2504 if (m_SoundModule != null) 2432 if (m_SoundModule != null)
2505 { 2433 {
2506 m_SoundModule.SendSound(m_host.UUID, 2434 m_SoundModule.SendSound(m_host.UUID,
2507 KeyOrName(sound, AssetType.Sound), volume, true, 0, 0, 2435 ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume, true, 0, 0,
2508 false, false); 2436 false, false);
2509 } 2437 }
2510 } 2438 }
@@ -2521,7 +2449,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2521 { 2449 {
2522 m_host.AddScriptLPS(1); 2450 m_host.AddScriptLPS(1);
2523 if (m_SoundModule != null) 2451 if (m_SoundModule != null)
2524 m_SoundModule.PreloadSound(m_host.UUID, KeyOrName(sound), 0); 2452 m_SoundModule.PreloadSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound), 0);
2525 ScriptSleep(1000); 2453 ScriptSleep(1000);
2526 } 2454 }
2527 2455
@@ -3352,7 +3280,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3352 if (presence != null) 3280 if (presence != null)
3353 { 3281 {
3354 // Do NOT try to parse UUID, animations cannot be triggered by ID 3282 // Do NOT try to parse UUID, animations cannot be triggered by ID
3355 UUID animID = InventoryKey(anim, (int)AssetType.Animation); 3283 UUID animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
3356 if (animID == UUID.Zero) 3284 if (animID == UUID.Zero)
3357 presence.Animator.AddAnimation(anim, m_host.UUID); 3285 presence.Animator.AddAnimation(anim, m_host.UUID);
3358 else 3286 else
@@ -3374,7 +3302,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3374 3302
3375 if (presence != null) 3303 if (presence != null)
3376 { 3304 {
3377 UUID animID = KeyOrName(anim); 3305 UUID animID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, anim);
3378 3306
3379 if (animID == UUID.Zero) 3307 if (animID == UUID.Zero)
3380 presence.Animator.RemoveAnimation(anim); 3308 presence.Animator.RemoveAnimation(anim);
@@ -4319,7 +4247,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4319 4247
4320 private void DoLLTeleport(ScenePresence sp, string destination, Vector3 targetPos, Vector3 targetLookAt) 4248 private void DoLLTeleport(ScenePresence sp, string destination, Vector3 targetPos, Vector3 targetLookAt)
4321 { 4249 {
4322 UUID assetID = KeyOrName(destination); 4250 UUID assetID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, destination);
4323 4251
4324 // The destinaion is not an asset ID and also doesn't name a landmark. 4252 // The destinaion is not an asset ID and also doesn't name a landmark.
4325 // Use it as a sim name 4253 // Use it as a sim name
@@ -4386,7 +4314,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4386 m_host.AddScriptLPS(1); 4314 m_host.AddScriptLPS(1);
4387 4315
4388 // TODO: Parameter check logic required. 4316 // TODO: Parameter check logic required.
4389 m_host.CollisionSound = KeyOrName(impact_sound, AssetType.Sound); 4317 m_host.CollisionSound = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound);
4390 m_host.CollisionSoundVolume = (float)impact_volume; 4318 m_host.CollisionSoundVolume = (float)impact_volume;
4391 } 4319 }
4392 4320
@@ -5912,7 +5840,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5912 if (m_SoundModule != null) 5840 if (m_SoundModule != null)
5913 { 5841 {
5914 m_SoundModule.TriggerSoundLimited(m_host.UUID, 5842 m_SoundModule.TriggerSoundLimited(m_host.UUID,
5915 KeyOrName(sound, AssetType.Sound), volume, 5843 ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume,
5916 bottom_south_west, top_north_east); 5844 bottom_south_west, top_north_east);
5917 } 5845 }
5918 } 5846 }
@@ -6346,7 +6274,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6346 break; 6274 break;
6347 6275
6348 case (int)ScriptBaseClass.PSYS_SRC_TEXTURE: 6276 case (int)ScriptBaseClass.PSYS_SRC_TEXTURE:
6349 prules.Texture = KeyOrName(rules.GetLSLStringItem(i + 1)); 6277 prules.Texture = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, rules.GetLSLStringItem(i + 1));
6350 break; 6278 break;
6351 6279
6352 case (int)ScriptBaseClass.PSYS_SRC_BURST_RATE: 6280 case (int)ScriptBaseClass.PSYS_SRC_BURST_RATE:
@@ -7269,9 +7197,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7269 UUID sculptId; 7197 UUID sculptId;
7270 7198
7271 if (!UUID.TryParse(map, out sculptId)) 7199 if (!UUID.TryParse(map, out sculptId))
7272 { 7200 sculptId = ScriptUtils.GetAssetIdFromItemName(m_host, map, (int)AssetType.Texture);
7273 sculptId = InventoryKey(map, (int)AssetType.Texture);
7274 }
7275 7201
7276 if (sculptId == UUID.Zero) 7202 if (sculptId == UUID.Zero)
7277 return; 7203 return;