diff options
author | Melanie | 2012-10-26 21:13:01 +0100 |
---|---|---|
committer | Melanie | 2012-10-26 21:13:01 +0100 |
commit | 26cc57b6cafda5168baab49cabe34d96f01dbd6d (patch) | |
tree | 94e078a75ab68825e64b15498f67d82988858dc9 /OpenSim/Region/ScriptEngine | |
parent | Merge branch 'master' into careminster (diff) | |
parent | minor: Make the error thrown logged when a simulator in grid mode is trying t... (diff) | |
download | opensim-SC-26cc57b6cafda5168baab49cabe34d96f01dbd6d.zip opensim-SC-26cc57b6cafda5168baab49cabe34d96f01dbd6d.tar.gz opensim-SC-26cc57b6cafda5168baab49cabe34d96f01dbd6d.tar.bz2 opensim-SC-26cc57b6cafda5168baab49cabe34d96f01dbd6d.tar.xz |
Merge branch 'master' into careminster
Conflicts:
OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs
OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs
OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs
OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
9 files changed, 365 insertions, 99 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index de49d6d..8d8df1d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | |||
@@ -11578,12 +11578,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
11578 | 11578 | ||
11579 | internal void Deprecated(string command) | 11579 | internal void Deprecated(string command) |
11580 | { | 11580 | { |
11581 | throw new Exception("Command deprecated: " + command); | 11581 | throw new ScriptException("Command deprecated: " + command); |
11582 | } | 11582 | } |
11583 | 11583 | ||
11584 | internal void LSLError(string msg) | 11584 | internal void LSLError(string msg) |
11585 | { | 11585 | { |
11586 | throw new Exception("LSL Runtime Error: " + msg); | 11586 | throw new ScriptException("LSL Runtime Error: " + msg); |
11587 | } | 11587 | } |
11588 | 11588 | ||
11589 | public delegate void AssetRequestCallback(UUID assetID, AssetBase asset); | 11589 | public delegate void AssetRequestCallback(UUID assetID, AssetBase asset); |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs index 6809c09..8f34833 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs | |||
@@ -95,13 +95,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
95 | 95 | ||
96 | internal void MODError(string msg) | 96 | internal void MODError(string msg) |
97 | { | 97 | { |
98 | throw new Exception("MOD Runtime Error: " + msg); | 98 | throw new ScriptException("MOD Runtime Error: " + msg); |
99 | } | 99 | } |
100 | 100 | ||
101 | // | 101 | /// <summary> |
102 | //Dumps an error message on the debug console. | 102 | /// Dumps an error message on the debug console. |
103 | // | 103 | /// </summary> |
104 | 104 | /// <param name='message'></param> | |
105 | internal void MODShoutError(string message) | 105 | internal void MODShoutError(string message) |
106 | { | 106 | { |
107 | if (message.Length > 1023) | 107 | if (message.Length > 1023) |
@@ -359,20 +359,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
359 | result[i] = (string)(LSL_String)plist[i]; | 359 | result[i] = (string)(LSL_String)plist[i]; |
360 | else if (plist[i] is LSL_Integer) | 360 | else if (plist[i] is LSL_Integer) |
361 | result[i] = (int)(LSL_Integer)plist[i]; | 361 | result[i] = (int)(LSL_Integer)plist[i]; |
362 | // The int check exists because of the many plain old int script constants in ScriptBase which | ||
363 | // are not LSL_Integers. | ||
364 | else if (plist[i] is int) | ||
365 | result[i] = plist[i]; | ||
362 | else if (plist[i] is LSL_Float) | 366 | else if (plist[i] is LSL_Float) |
363 | result[i] = (float)(LSL_Float)plist[i]; | 367 | result[i] = (float)(LSL_Float)plist[i]; |
364 | else if (plist[i] is LSL_Key) | 368 | else if (plist[i] is LSL_Key) |
365 | result[i] = new UUID((LSL_Key)plist[i]); | 369 | result[i] = new UUID((LSL_Key)plist[i]); |
366 | else if (plist[i] is LSL_Rotation) | 370 | else if (plist[i] is LSL_Rotation) |
367 | { | 371 | result[i] = (Quaternion)((LSL_Rotation)plist[i]); |
368 | result[i] = (OpenMetaverse.Quaternion)( | ||
369 | (LSL_Rotation)plist[i]); | ||
370 | } | ||
371 | else if (plist[i] is LSL_Vector) | 372 | else if (plist[i] is LSL_Vector) |
372 | { | 373 | result[i] = (Vector3)((LSL_Vector)plist[i]); |
373 | result[i] = (OpenMetaverse.Vector3)( | ||
374 | (LSL_Vector)plist[i]); | ||
375 | } | ||
376 | else | 374 | else |
377 | MODError(String.Format("{0}: unknown LSL list element type", fname)); | 375 | MODError(String.Format("{0}: unknown LSL list element type", fname)); |
378 | } | 376 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 17277d7..51c8c7e 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | |||
@@ -218,7 +218,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
218 | } | 218 | } |
219 | else | 219 | else |
220 | { | 220 | { |
221 | throw new Exception("OSSL Runtime Error: " + msg); | 221 | throw new ScriptException("OSSL Runtime Error: " + msg); |
222 | } | 222 | } |
223 | } | 223 | } |
224 | 224 | ||
@@ -1789,18 +1789,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1789 | protected string LoadNotecard(string notecardNameOrUuid) | 1789 | protected string LoadNotecard(string notecardNameOrUuid) |
1790 | { | 1790 | { |
1791 | UUID assetID = CacheNotecard(notecardNameOrUuid); | 1791 | UUID assetID = CacheNotecard(notecardNameOrUuid); |
1792 | StringBuilder notecardData = new StringBuilder(); | ||
1793 | 1792 | ||
1794 | for (int count = 0; count < NotecardCache.GetLines(assetID); count++) | 1793 | if (assetID != UUID.Zero) |
1795 | { | 1794 | { |
1796 | string line = NotecardCache.GetLine(assetID, count) + "\n"; | 1795 | StringBuilder notecardData = new StringBuilder(); |
1797 | 1796 | ||
1798 | // m_log.DebugFormat("[OSSL]: From notecard {0} loading line {1}", notecardNameOrUuid, line); | 1797 | for (int count = 0; count < NotecardCache.GetLines(assetID); count++) |
1799 | 1798 | { | |
1800 | notecardData.Append(line); | 1799 | string line = NotecardCache.GetLine(assetID, count) + "\n"; |
1800 | |||
1801 | // m_log.DebugFormat("[OSSL]: From notecard {0} loading line {1}", notecardNameOrUuid, line); | ||
1802 | |||
1803 | notecardData.Append(line); | ||
1804 | } | ||
1805 | |||
1806 | return notecardData.ToString(); | ||
1801 | } | 1807 | } |
1802 | 1808 | ||
1803 | return notecardData.ToString(); | 1809 | return null; |
1804 | } | 1810 | } |
1805 | 1811 | ||
1806 | /// <summary> | 1812 | /// <summary> |
@@ -2373,11 +2379,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2373 | return UUID.Zero.ToString(); | 2379 | return UUID.Zero.ToString(); |
2374 | } | 2380 | } |
2375 | } | 2381 | } |
2382 | else | ||
2383 | { | ||
2384 | OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard)); | ||
2385 | } | ||
2376 | } | 2386 | } |
2377 | 2387 | ||
2378 | if (appearance == null) | ||
2379 | return new LSL_Key(UUID.Zero.ToString()); | ||
2380 | |||
2381 | UUID ownerID = UUID.Zero; | 2388 | UUID ownerID = UUID.Zero; |
2382 | if (owned) | 2389 | if (owned) |
2383 | ownerID = m_host.OwnerID; | 2390 | ownerID = m_host.OwnerID; |
@@ -2446,6 +2453,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2446 | return; | 2453 | return; |
2447 | 2454 | ||
2448 | string appearanceSerialized = LoadNotecard(notecard); | 2455 | string appearanceSerialized = LoadNotecard(notecard); |
2456 | |||
2457 | if (appearanceSerialized == null) | ||
2458 | OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard)); | ||
2459 | |||
2449 | OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized); | 2460 | OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized); |
2450 | // OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized); | 2461 | // OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized); |
2451 | // Console.WriteLine("appearanceSerialized {0}", appearanceSerialized); | 2462 | // Console.WriteLine("appearanceSerialized {0}", appearanceSerialized); |
@@ -3691,5 +3702,68 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3691 | 3702 | ||
3692 | DropAttachmentAt(false, pos, rot); | 3703 | DropAttachmentAt(false, pos, rot); |
3693 | } | 3704 | } |
3705 | |||
3706 | public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield) | ||
3707 | { | ||
3708 | CheckThreatLevel(ThreatLevel.Low, "osListenRegex"); | ||
3709 | m_host.AddScriptLPS(1); | ||
3710 | UUID keyID; | ||
3711 | UUID.TryParse(ID, out keyID); | ||
3712 | |||
3713 | // if we want the name to be used as a regular expression, ensure it is valid first. | ||
3714 | if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_NAME) == ScriptBaseClass.OS_LISTEN_REGEX_NAME) | ||
3715 | { | ||
3716 | try | ||
3717 | { | ||
3718 | Regex.IsMatch("", name); | ||
3719 | } | ||
3720 | catch (Exception) | ||
3721 | { | ||
3722 | OSSLShoutError("Name regex is invalid."); | ||
3723 | return -1; | ||
3724 | } | ||
3725 | } | ||
3726 | |||
3727 | // if we want the msg to be used as a regular expression, ensure it is valid first. | ||
3728 | if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE) == ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE) | ||
3729 | { | ||
3730 | try | ||
3731 | { | ||
3732 | Regex.IsMatch("", msg); | ||
3733 | } | ||
3734 | catch (Exception) | ||
3735 | { | ||
3736 | OSSLShoutError("Message regex is invalid."); | ||
3737 | return -1; | ||
3738 | } | ||
3739 | } | ||
3740 | |||
3741 | IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); | ||
3742 | return (wComm == null) ? -1 : wComm.Listen( | ||
3743 | m_host.LocalId, | ||
3744 | m_item.ItemID, | ||
3745 | m_host.UUID, | ||
3746 | channelID, | ||
3747 | name, | ||
3748 | keyID, | ||
3749 | msg, | ||
3750 | regexBitfield | ||
3751 | ); | ||
3752 | } | ||
3753 | |||
3754 | public LSL_Integer osRegexIsMatch(string input, string pattern) | ||
3755 | { | ||
3756 | CheckThreatLevel(ThreatLevel.Low, "osRegexIsMatch"); | ||
3757 | m_host.AddScriptLPS(1); | ||
3758 | try | ||
3759 | { | ||
3760 | return Regex.IsMatch(input, pattern) ? 1 : 0; | ||
3761 | } | ||
3762 | catch (Exception) | ||
3763 | { | ||
3764 | OSSLShoutError("Possible invalid regular expression detected."); | ||
3765 | return 0; | ||
3766 | } | ||
3767 | } | ||
3694 | } | 3768 | } |
3695 | } | 3769 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index b1fbed5..c447d1f 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | |||
@@ -418,5 +418,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
418 | /// <param name="pos"></param> | 418 | /// <param name="pos"></param> |
419 | /// <param name="rot"></param> | 419 | /// <param name="rot"></param> |
420 | void osForceDropAttachmentAt(vector pos, rotation rot); | 420 | void osForceDropAttachmentAt(vector pos, rotation rot); |
421 | |||
422 | /// <summary> | ||
423 | /// Identical to llListen except for a bitfield which indicates which | ||
424 | /// string parameters should be parsed as regex patterns. | ||
425 | /// </summary> | ||
426 | /// <param name="channelID"></param> | ||
427 | /// <param name="name"></param> | ||
428 | /// <param name="ID"></param> | ||
429 | /// <param name="msg"></param> | ||
430 | /// <param name="regexBitfield"> | ||
431 | /// OS_LISTEN_REGEX_NAME | ||
432 | /// OS_LISTEN_REGEX_MESSAGE | ||
433 | /// </param> | ||
434 | /// <returns></returns> | ||
435 | LSL_Integer osListenRegex(int channelID, string name, string ID, | ||
436 | string msg, int regexBitfield); | ||
437 | |||
438 | /// <summary> | ||
439 | /// Wraps to bool Regex.IsMatch(string input, string pattern) | ||
440 | /// </summary> | ||
441 | /// <param name="input">string to test for match</param> | ||
442 | /// <param name="regex">string to use as pattern</param> | ||
443 | /// <returns>boolean</returns> | ||
444 | LSL_Integer osRegexIsMatch(string input, string pattern); | ||
421 | } | 445 | } |
422 | } | 446 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs index bf66eb6..0dd5a57 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs | |||
@@ -741,5 +741,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
741 | public const int KFM_CMD_PLAY = 0; | 741 | public const int KFM_CMD_PLAY = 0; |
742 | public const int KFM_CMD_STOP = 1; | 742 | public const int KFM_CMD_STOP = 1; |
743 | public const int KFM_CMD_PAUSE = 2; | 743 | public const int KFM_CMD_PAUSE = 2; |
744 | |||
745 | /// <summary> | ||
746 | /// process name parameter as regex | ||
747 | /// </summary> | ||
748 | public const int OS_LISTEN_REGEX_NAME = 0x1; | ||
749 | |||
750 | /// <summary> | ||
751 | /// process message parameter as regex | ||
752 | /// </summary> | ||
753 | public const int OS_LISTEN_REGEX_MESSAGE = 0x2; | ||
744 | } | 754 | } |
745 | } | 755 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index dee1b28..afa9ae0 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | |||
@@ -992,5 +992,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
992 | { | 992 | { |
993 | m_OSSL_Functions.osForceDropAttachmentAt(pos, rot); | 993 | m_OSSL_Functions.osForceDropAttachmentAt(pos, rot); |
994 | } | 994 | } |
995 | |||
996 | public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield) | ||
997 | { | ||
998 | return m_OSSL_Functions.osListenRegex(channelID, name, ID, msg, regexBitfield); | ||
999 | } | ||
1000 | |||
1001 | public LSL_Integer osRegexIsMatch(string input, string pattern) | ||
1002 | { | ||
1003 | return m_OSSL_Functions.osRegexIsMatch(input, pattern); | ||
1004 | } | ||
995 | } | 1005 | } |
996 | } | 1006 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/ScriptException.cs b/OpenSim/Region/ScriptEngine/Shared/ScriptException.cs new file mode 100644 index 0000000..ae67fc5 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/Shared/ScriptException.cs | |||
@@ -0,0 +1,40 @@ | |||
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 | |||
30 | namespace OpenSim.Region.ScriptEngine.Shared | ||
31 | { | ||
32 | public class ScriptException : Exception | ||
33 | { | ||
34 | public ScriptException() : base() {} | ||
35 | |||
36 | public ScriptException(string message) : base(message) {} | ||
37 | |||
38 | public ScriptException(string message, Exception innerException) : base(message, innerException) {} | ||
39 | } | ||
40 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs index c8718d9..c401794 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs | |||
@@ -75,76 +75,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
75 | m_engine.AddRegion(m_scene); | 75 | m_engine.AddRegion(m_scene); |
76 | } | 76 | } |
77 | 77 | ||
78 | /// <summary> | ||
79 | /// Test creation of an NPC where the appearance data comes from a notecard | ||
80 | /// </summary> | ||
81 | [Test] | ||
82 | public void TestOsNpcCreateUsingAppearanceFromNotecard() | ||
83 | { | ||
84 | TestHelpers.InMethod(); | ||
85 | // log4net.Config.XmlConfigurator.Configure(); | ||
86 | |||
87 | // Store an avatar with a different height from default in a notecard. | ||
88 | UUID userId = TestHelpers.ParseTail(0x1); | ||
89 | float newHeight = 1.9f; | ||
90 | |||
91 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); | ||
92 | sp.Appearance.AvatarHeight = newHeight; | ||
93 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10); | ||
94 | SceneObjectPart part = so.RootPart; | ||
95 | m_scene.AddSceneObject(so); | ||
96 | |||
97 | OSSL_Api osslApi = new OSSL_Api(); | ||
98 | osslApi.Initialize(m_engine, part, null); | ||
99 | |||
100 | string notecardName = "appearanceNc"; | ||
101 | osslApi.osOwnerSaveAppearance(notecardName); | ||
102 | |||
103 | // Try creating a bot using the appearance in the notecard. | ||
104 | string npcRaw = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName); | ||
105 | Assert.That(npcRaw, Is.Not.Null); | ||
106 | |||
107 | UUID npcId = new UUID(npcRaw); | ||
108 | ScenePresence npc = m_scene.GetScenePresence(npcId); | ||
109 | Assert.That(npc, Is.Not.Null); | ||
110 | Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(newHeight)); | ||
111 | } | ||
112 | |||
113 | /// <summary> | ||
114 | /// Test creation of an NPC where the appearance data comes from an avatar already in the region. | ||
115 | /// </summary> | ||
116 | [Test] | ||
117 | public void TestOsNpcCreateUsingAppearanceFromAvatar() | ||
118 | { | ||
119 | TestHelpers.InMethod(); | ||
120 | // TestHelpers.EnableLogging(); | ||
121 | |||
122 | // Store an avatar with a different height from default in a notecard. | ||
123 | UUID userId = TestHelpers.ParseTail(0x1); | ||
124 | float newHeight = 1.9f; | ||
125 | |||
126 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); | ||
127 | sp.Appearance.AvatarHeight = newHeight; | ||
128 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10); | ||
129 | SceneObjectPart part = so.RootPart; | ||
130 | m_scene.AddSceneObject(so); | ||
131 | |||
132 | OSSL_Api osslApi = new OSSL_Api(); | ||
133 | osslApi.Initialize(m_engine, part, null); | ||
134 | |||
135 | string notecardName = "appearanceNc"; | ||
136 | osslApi.osOwnerSaveAppearance(notecardName); | ||
137 | |||
138 | // Try creating a bot using the existing avatar's appearance | ||
139 | string npcRaw = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), sp.UUID.ToString()); | ||
140 | Assert.That(npcRaw, Is.Not.Null); | ||
141 | |||
142 | UUID npcId = new UUID(npcRaw); | ||
143 | ScenePresence npc = m_scene.GetScenePresence(npcId); | ||
144 | Assert.That(npc, Is.Not.Null); | ||
145 | Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(newHeight)); | ||
146 | } | ||
147 | |||
148 | [Test] | 78 | [Test] |
149 | public void TestOsOwnerSaveAppearance() | 79 | public void TestOsOwnerSaveAppearance() |
150 | { | 80 | { |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs index 25679a6..b49bcc2 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs | |||
@@ -36,6 +36,7 @@ using OpenMetaverse; | |||
36 | using OpenMetaverse.Assets; | 36 | using OpenMetaverse.Assets; |
37 | using OpenMetaverse.StructuredData; | 37 | using OpenMetaverse.StructuredData; |
38 | using OpenSim.Framework; | 38 | using OpenSim.Framework; |
39 | using OpenSim.Region.CoreModules.Avatar.Attachments; | ||
39 | using OpenSim.Region.CoreModules.Avatar.AvatarFactory; | 40 | using OpenSim.Region.CoreModules.Avatar.AvatarFactory; |
40 | using OpenSim.Region.OptionalModules.World.NPC; | 41 | using OpenSim.Region.OptionalModules.World.NPC; |
41 | using OpenSim.Region.Framework.Scenes; | 42 | using OpenSim.Region.Framework.Scenes; |
@@ -71,7 +72,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
71 | config.Set("Enabled", "true"); | 72 | config.Set("Enabled", "true"); |
72 | 73 | ||
73 | m_scene = new SceneHelpers().SetupScene(); | 74 | m_scene = new SceneHelpers().SetupScene(); |
74 | SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule()); | 75 | SceneHelpers.SetupSceneModules( |
76 | m_scene, initConfigSource, new AvatarFactoryModule(), new AttachmentsModule(), new NPCModule()); | ||
75 | 77 | ||
76 | m_engine = new XEngine.XEngine(); | 78 | m_engine = new XEngine.XEngine(); |
77 | m_engine.Initialise(initConfigSource); | 79 | m_engine.Initialise(initConfigSource); |
@@ -79,13 +81,191 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
79 | } | 81 | } |
80 | 82 | ||
81 | /// <summary> | 83 | /// <summary> |
84 | /// Test creation of an NPC where the appearance data comes from a notecard | ||
85 | /// </summary> | ||
86 | [Test] | ||
87 | public void TestOsNpcCreateUsingAppearanceFromNotecard() | ||
88 | { | ||
89 | TestHelpers.InMethod(); | ||
90 | |||
91 | // Store an avatar with a different height from default in a notecard. | ||
92 | UUID userId = TestHelpers.ParseTail(0x1); | ||
93 | float newHeight = 1.9f; | ||
94 | |||
95 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); | ||
96 | sp.Appearance.AvatarHeight = newHeight; | ||
97 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10); | ||
98 | SceneObjectPart part = so.RootPart; | ||
99 | m_scene.AddSceneObject(so); | ||
100 | |||
101 | OSSL_Api osslApi = new OSSL_Api(); | ||
102 | osslApi.Initialize(m_engine, part, null); | ||
103 | |||
104 | string notecardName = "appearanceNc"; | ||
105 | osslApi.osOwnerSaveAppearance(notecardName); | ||
106 | |||
107 | // Try creating a bot using the appearance in the notecard. | ||
108 | string npcRaw = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName); | ||
109 | Assert.That(npcRaw, Is.Not.Null); | ||
110 | |||
111 | UUID npcId = new UUID(npcRaw); | ||
112 | ScenePresence npc = m_scene.GetScenePresence(npcId); | ||
113 | Assert.That(npc, Is.Not.Null); | ||
114 | Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(newHeight)); | ||
115 | } | ||
116 | |||
117 | [Test] | ||
118 | public void TestOsNpcCreateNotExistingNotecard() | ||
119 | { | ||
120 | TestHelpers.InMethod(); | ||
121 | |||
122 | UUID userId = TestHelpers.ParseTail(0x1); | ||
123 | |||
124 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10); | ||
125 | m_scene.AddSceneObject(so); | ||
126 | |||
127 | OSSL_Api osslApi = new OSSL_Api(); | ||
128 | osslApi.Initialize(m_engine, so.RootPart, null); | ||
129 | |||
130 | string npcRaw; | ||
131 | bool gotExpectedException = false; | ||
132 | try | ||
133 | { | ||
134 | npcRaw | ||
135 | = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), "not existing notecard name"); | ||
136 | } | ||
137 | catch (ScriptException) | ||
138 | { | ||
139 | gotExpectedException = true; | ||
140 | } | ||
141 | |||
142 | Assert.That(gotExpectedException, Is.True); | ||
143 | } | ||
144 | |||
145 | /// <summary> | ||
146 | /// Test creation of an NPC where the appearance data comes from an avatar already in the region. | ||
147 | /// </summary> | ||
148 | [Test] | ||
149 | public void TestOsNpcCreateUsingAppearanceFromAvatar() | ||
150 | { | ||
151 | TestHelpers.InMethod(); | ||
152 | // TestHelpers.EnableLogging(); | ||
153 | |||
154 | // Store an avatar with a different height from default in a notecard. | ||
155 | UUID userId = TestHelpers.ParseTail(0x1); | ||
156 | float newHeight = 1.9f; | ||
157 | |||
158 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); | ||
159 | sp.Appearance.AvatarHeight = newHeight; | ||
160 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10); | ||
161 | SceneObjectPart part = so.RootPart; | ||
162 | m_scene.AddSceneObject(so); | ||
163 | |||
164 | OSSL_Api osslApi = new OSSL_Api(); | ||
165 | osslApi.Initialize(m_engine, part, null); | ||
166 | |||
167 | string notecardName = "appearanceNc"; | ||
168 | osslApi.osOwnerSaveAppearance(notecardName); | ||
169 | |||
170 | // Try creating a bot using the existing avatar's appearance | ||
171 | string npcRaw = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), sp.UUID.ToString()); | ||
172 | Assert.That(npcRaw, Is.Not.Null); | ||
173 | |||
174 | UUID npcId = new UUID(npcRaw); | ||
175 | ScenePresence npc = m_scene.GetScenePresence(npcId); | ||
176 | Assert.That(npc, Is.Not.Null); | ||
177 | Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(newHeight)); | ||
178 | } | ||
179 | |||
180 | [Test] | ||
181 | public void TestOsNpcLoadAppearance() | ||
182 | { | ||
183 | TestHelpers.InMethod(); | ||
184 | |||
185 | // Store an avatar with a different height from default in a notecard. | ||
186 | UUID userId = TestHelpers.ParseTail(0x1); | ||
187 | float firstHeight = 1.9f; | ||
188 | float secondHeight = 2.1f; | ||
189 | string firstAppearanceNcName = "appearanceNc1"; | ||
190 | string secondAppearanceNcName = "appearanceNc2"; | ||
191 | |||
192 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); | ||
193 | sp.Appearance.AvatarHeight = firstHeight; | ||
194 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10); | ||
195 | SceneObjectPart part = so.RootPart; | ||
196 | m_scene.AddSceneObject(so); | ||
197 | |||
198 | OSSL_Api osslApi = new OSSL_Api(); | ||
199 | osslApi.Initialize(m_engine, part, null); | ||
200 | |||
201 | osslApi.osOwnerSaveAppearance(firstAppearanceNcName); | ||
202 | |||
203 | string npcRaw | ||
204 | = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), firstAppearanceNcName); | ||
205 | |||
206 | // Create a second appearance notecard with a different height | ||
207 | sp.Appearance.AvatarHeight = secondHeight; | ||
208 | osslApi.osOwnerSaveAppearance(secondAppearanceNcName); | ||
209 | |||
210 | osslApi.osNpcLoadAppearance(npcRaw, secondAppearanceNcName); | ||
211 | |||
212 | UUID npcId = new UUID(npcRaw); | ||
213 | ScenePresence npc = m_scene.GetScenePresence(npcId); | ||
214 | Assert.That(npc, Is.Not.Null); | ||
215 | Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(secondHeight)); | ||
216 | } | ||
217 | |||
218 | [Test] | ||
219 | public void TestOsNpcLoadAppearanceNotExistingNotecard() | ||
220 | { | ||
221 | TestHelpers.InMethod(); | ||
222 | |||
223 | // Store an avatar with a different height from default in a notecard. | ||
224 | UUID userId = TestHelpers.ParseTail(0x1); | ||
225 | float firstHeight = 1.9f; | ||
226 | float secondHeight = 2.1f; | ||
227 | string firstAppearanceNcName = "appearanceNc1"; | ||
228 | string secondAppearanceNcName = "appearanceNc2"; | ||
229 | |||
230 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); | ||
231 | sp.Appearance.AvatarHeight = firstHeight; | ||
232 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10); | ||
233 | SceneObjectPart part = so.RootPart; | ||
234 | m_scene.AddSceneObject(so); | ||
235 | |||
236 | OSSL_Api osslApi = new OSSL_Api(); | ||
237 | osslApi.Initialize(m_engine, part, null); | ||
238 | |||
239 | osslApi.osOwnerSaveAppearance(firstAppearanceNcName); | ||
240 | |||
241 | string npcRaw | ||
242 | = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), firstAppearanceNcName); | ||
243 | |||
244 | bool gotExpectedException = false; | ||
245 | try | ||
246 | { | ||
247 | osslApi.osNpcLoadAppearance(npcRaw, secondAppearanceNcName); | ||
248 | } | ||
249 | catch (ScriptException) | ||
250 | { | ||
251 | gotExpectedException = true; | ||
252 | } | ||
253 | |||
254 | Assert.That(gotExpectedException, Is.True); | ||
255 | |||
256 | UUID npcId = new UUID(npcRaw); | ||
257 | ScenePresence npc = m_scene.GetScenePresence(npcId); | ||
258 | Assert.That(npc, Is.Not.Null); | ||
259 | Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(firstHeight)); | ||
260 | } | ||
261 | |||
262 | /// <summary> | ||
82 | /// Test removal of an owned NPC. | 263 | /// Test removal of an owned NPC. |
83 | /// </summary> | 264 | /// </summary> |
84 | [Test] | 265 | [Test] |
85 | public void TestOsNpcRemoveOwned() | 266 | public void TestOsNpcRemoveOwned() |
86 | { | 267 | { |
87 | TestHelpers.InMethod(); | 268 | TestHelpers.InMethod(); |
88 | // log4net.Config.XmlConfigurator.Configure(); | ||
89 | 269 | ||
90 | // Store an avatar with a different height from default in a notecard. | 270 | // Store an avatar with a different height from default in a notecard. |
91 | UUID userId = TestHelpers.ParseTail(0x1); | 271 | UUID userId = TestHelpers.ParseTail(0x1); |