diff options
author | Melanie | 2012-01-06 21:37:01 +0100 |
---|---|---|
committer | Melanie | 2012-01-06 21:37:01 +0100 |
commit | de9d6096a5b1ddc8b7dfa57bffb73493b223df59 (patch) | |
tree | ef7147b4fd0958f559ad513e36f25ab3eca96842 | |
parent | Add osNpcCreateOwned to create an owned NPC. Those can be sensed only by the ... (diff) | |
parent | Merge branch 'master' into careminster (diff) | |
download | opensim-SC_OLD-de9d6096a5b1ddc8b7dfa57bffb73493b223df59.zip opensim-SC_OLD-de9d6096a5b1ddc8b7dfa57bffb73493b223df59.tar.gz opensim-SC_OLD-de9d6096a5b1ddc8b7dfa57bffb73493b223df59.tar.bz2 opensim-SC_OLD-de9d6096a5b1ddc8b7dfa57bffb73493b223df59.tar.xz |
Merge branch 'master' of ssh://3dhosting.de/var/git/careminster
8 files changed, 519 insertions, 54 deletions
diff --git a/OpenSim/Capabilities/Handlers/FetchInventory2/FetchInventory2Handler.cs b/OpenSim/Capabilities/Handlers/FetchInventory2/FetchInventory2Handler.cs new file mode 100644 index 0000000..717a097 --- /dev/null +++ b/OpenSim/Capabilities/Handlers/FetchInventory2/FetchInventory2Handler.cs | |||
@@ -0,0 +1,148 @@ | |||
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.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | using log4net; | ||
33 | using Nini.Config; | ||
34 | using OpenMetaverse; | ||
35 | using OpenMetaverse.StructuredData; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Framework.Capabilities; | ||
38 | using OpenSim.Region.Framework.Interfaces; | ||
39 | using OpenSim.Framework.Servers.HttpServer; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using Caps = OpenSim.Framework.Capabilities.Caps; | ||
42 | using OSDArray = OpenMetaverse.StructuredData.OSDArray; | ||
43 | using OSDMap = OpenMetaverse.StructuredData.OSDMap; | ||
44 | |||
45 | namespace OpenSim.Capabilities.Handlers | ||
46 | { | ||
47 | public class FetchInventory2Handler | ||
48 | { | ||
49 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
51 | private IInventoryService m_inventoryService; | ||
52 | |||
53 | public FetchInventory2Handler(IInventoryService invService) | ||
54 | { | ||
55 | m_inventoryService = invService; | ||
56 | } | ||
57 | |||
58 | public string FetchInventoryRequest(string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
59 | { | ||
60 | // m_log.DebugFormat("[FETCH INVENTORY HANDLER]: Received FetchInventory capabilty request"); | ||
61 | |||
62 | OSDMap requestmap = (OSDMap)OSDParser.DeserializeLLSDXml(Utils.StringToBytes(request)); | ||
63 | OSDArray itemsRequested = (OSDArray)requestmap["items"]; | ||
64 | |||
65 | string reply; | ||
66 | LLSDFetchInventory llsdReply = new LLSDFetchInventory(); | ||
67 | |||
68 | foreach (OSDMap osdItemId in itemsRequested) | ||
69 | { | ||
70 | UUID itemId = osdItemId["item_id"].AsUUID(); | ||
71 | |||
72 | InventoryItemBase item = m_inventoryService.GetItem(new InventoryItemBase(itemId)); | ||
73 | |||
74 | if (item != null) | ||
75 | { | ||
76 | // We don't know the agent that this request belongs to so we'll use the agent id of the item | ||
77 | // which will be the same for all items. | ||
78 | llsdReply.agent_id = item.Owner; | ||
79 | |||
80 | llsdReply.items.Array.Add(ConvertInventoryItem(item)); | ||
81 | } | ||
82 | } | ||
83 | |||
84 | reply = LLSDHelpers.SerialiseLLSDReply(llsdReply); | ||
85 | |||
86 | return reply; | ||
87 | } | ||
88 | |||
89 | /// <summary> | ||
90 | /// Convert an internal inventory item object into an LLSD object. | ||
91 | /// </summary> | ||
92 | /// <param name="invItem"></param> | ||
93 | /// <returns></returns> | ||
94 | private LLSDInventoryItem ConvertInventoryItem(InventoryItemBase invItem) | ||
95 | { | ||
96 | LLSDInventoryItem llsdItem = new LLSDInventoryItem(); | ||
97 | llsdItem.asset_id = invItem.AssetID; | ||
98 | llsdItem.created_at = invItem.CreationDate; | ||
99 | llsdItem.desc = invItem.Description; | ||
100 | llsdItem.flags = (int)invItem.Flags; | ||
101 | llsdItem.item_id = invItem.ID; | ||
102 | llsdItem.name = invItem.Name; | ||
103 | llsdItem.parent_id = invItem.Folder; | ||
104 | |||
105 | try | ||
106 | { | ||
107 | llsdItem.type = Utils.AssetTypeToString((AssetType)invItem.AssetType); | ||
108 | llsdItem.inv_type = Utils.InventoryTypeToString((InventoryType)invItem.InvType); | ||
109 | } | ||
110 | catch (Exception e) | ||
111 | { | ||
112 | m_log.ErrorFormat( | ||
113 | "[WEB FETCH INV DESC HANDLER]: Problem setting asset {0} inventory {1} types while converting inventory item {2}: {3}", | ||
114 | invItem.AssetType, invItem.InvType, invItem.Name, e.Message); | ||
115 | } | ||
116 | |||
117 | llsdItem.permissions = new LLSDPermissions(); | ||
118 | llsdItem.permissions.creator_id = invItem.CreatorIdAsUuid; | ||
119 | llsdItem.permissions.base_mask = (int)invItem.CurrentPermissions; | ||
120 | llsdItem.permissions.everyone_mask = (int)invItem.EveryOnePermissions; | ||
121 | llsdItem.permissions.group_id = invItem.GroupID; | ||
122 | llsdItem.permissions.group_mask = (int)invItem.GroupPermissions; | ||
123 | llsdItem.permissions.is_owner_group = invItem.GroupOwned; | ||
124 | llsdItem.permissions.next_owner_mask = (int)invItem.NextPermissions; | ||
125 | llsdItem.permissions.owner_id = invItem.Owner; | ||
126 | llsdItem.permissions.owner_mask = (int)invItem.CurrentPermissions; | ||
127 | llsdItem.sale_info = new LLSDSaleInfo(); | ||
128 | llsdItem.sale_info.sale_price = invItem.SalePrice; | ||
129 | switch (invItem.SaleType) | ||
130 | { | ||
131 | default: | ||
132 | llsdItem.sale_info.sale_type = "not"; | ||
133 | break; | ||
134 | case 1: | ||
135 | llsdItem.sale_info.sale_type = "original"; | ||
136 | break; | ||
137 | case 2: | ||
138 | llsdItem.sale_info.sale_type = "copy"; | ||
139 | break; | ||
140 | case 3: | ||
141 | llsdItem.sale_info.sale_type = "contents"; | ||
142 | break; | ||
143 | } | ||
144 | |||
145 | return llsdItem; | ||
146 | } | ||
147 | } | ||
148 | } | ||
diff --git a/OpenSim/Capabilities/Handlers/FetchInventory2/FetchInventory2ServerConnector.cs b/OpenSim/Capabilities/Handlers/FetchInventory2/FetchInventory2ServerConnector.cs new file mode 100644 index 0000000..0ba8931 --- /dev/null +++ b/OpenSim/Capabilities/Handlers/FetchInventory2/FetchInventory2ServerConnector.cs | |||
@@ -0,0 +1,70 @@ | |||
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 Nini.Config; | ||
30 | using OpenSim.Server.Base; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using OpenSim.Framework.Servers.HttpServer; | ||
33 | using OpenSim.Server.Handlers.Base; | ||
34 | using OpenMetaverse; | ||
35 | |||
36 | namespace OpenSim.Capabilities.Handlers | ||
37 | { | ||
38 | public class FetchInventory2ServerConnector : ServiceConnector | ||
39 | { | ||
40 | private IInventoryService m_InventoryService; | ||
41 | private string m_ConfigName = "CapsService"; | ||
42 | |||
43 | public FetchInventory2ServerConnector(IConfigSource config, IHttpServer server, string configName) | ||
44 | : base(config, server, configName) | ||
45 | { | ||
46 | if (configName != String.Empty) | ||
47 | m_ConfigName = configName; | ||
48 | |||
49 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
50 | if (serverConfig == null) | ||
51 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); | ||
52 | |||
53 | string invService = serverConfig.GetString("InventoryService", String.Empty); | ||
54 | |||
55 | if (invService == String.Empty) | ||
56 | throw new Exception("No InventoryService in config file"); | ||
57 | |||
58 | Object[] args = new Object[] { config }; | ||
59 | m_InventoryService = ServerUtils.LoadPlugin<IInventoryService>(invService, args); | ||
60 | |||
61 | if (m_InventoryService == null) | ||
62 | throw new Exception(String.Format("Failed to load InventoryService from {0}; config is {1}", invService, m_ConfigName)); | ||
63 | |||
64 | FetchInventory2Handler fiHandler = new FetchInventory2Handler(m_InventoryService); | ||
65 | IRequestHandler reqHandler | ||
66 | = new RestStreamHandler("POST", "/CAPS/FetchInventory/", fiHandler.FetchInventoryRequest); | ||
67 | server.AddStreamHandler(reqHandler); | ||
68 | } | ||
69 | } | ||
70 | } | ||
diff --git a/OpenSim/Capabilities/Handlers/WebFetchInventoryDescendents/WebFetchInvDescHandler.cs b/OpenSim/Capabilities/Handlers/WebFetchInventoryDescendents/WebFetchInvDescHandler.cs index 3ce4e66..8b44f72 100644 --- a/OpenSim/Capabilities/Handlers/WebFetchInventoryDescendents/WebFetchInvDescHandler.cs +++ b/OpenSim/Capabilities/Handlers/WebFetchInventoryDescendents/WebFetchInvDescHandler.cs | |||
@@ -245,7 +245,7 @@ namespace OpenSim.Capabilities.Handlers | |||
245 | // containingFolder.Name, containingFolder.ID, agentID); | 245 | // containingFolder.Name, containingFolder.ID, agentID); |
246 | 246 | ||
247 | version = containingFolder.Version; | 247 | version = containingFolder.Version; |
248 | // | 248 | |
249 | // if (fetchItems) | 249 | // if (fetchItems) |
250 | // { | 250 | // { |
251 | // List<InventoryItemBase> linkedItemsToAdd = new List<InventoryItemBase>(); | 251 | // List<InventoryItemBase> linkedItemsToAdd = new List<InventoryItemBase>(); |
diff --git a/OpenSim/Capabilities/LLSDInventoryItem.cs b/OpenSim/Capabilities/LLSDInventoryItem.cs index cce18d7..426a6cb 100644 --- a/OpenSim/Capabilities/LLSDInventoryItem.cs +++ b/OpenSim/Capabilities/LLSDInventoryItem.cs | |||
@@ -95,4 +95,11 @@ namespace OpenSim.Framework.Capabilities | |||
95 | public UUID owner_id; | 95 | public UUID owner_id; |
96 | public int version; | 96 | public int version; |
97 | } | 97 | } |
98 | } | 98 | |
99 | [OSDMap] | ||
100 | public class LLSDFetchInventory | ||
101 | { | ||
102 | public UUID agent_id; | ||
103 | public OSDArray items = new OSDArray(); | ||
104 | } | ||
105 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/FetchInventory2Module.cs b/OpenSim/Region/ClientStack/Linden/Caps/FetchInventory2Module.cs new file mode 100644 index 0000000..14501c7 --- /dev/null +++ b/OpenSim/Region/ClientStack/Linden/Caps/FetchInventory2Module.cs | |||
@@ -0,0 +1,151 @@ | |||
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.Collections; | ||
30 | using System.Reflection; | ||
31 | using log4net; | ||
32 | using Nini.Config; | ||
33 | using Mono.Addins; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Services.Interfaces; | ||
40 | using Caps = OpenSim.Framework.Capabilities.Caps; | ||
41 | using OpenSim.Capabilities.Handlers; | ||
42 | |||
43 | namespace OpenSim.Region.ClientStack.Linden | ||
44 | { | ||
45 | /// <summary> | ||
46 | /// This module implements both WebFetchInventoryDescendents and FetchInventoryDescendents2 capabilities. | ||
47 | /// </summary> | ||
48 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] | ||
49 | public class FetchInventory2Module : INonSharedRegionModule | ||
50 | { | ||
51 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
52 | |||
53 | public bool Enabled { get; private set; } | ||
54 | |||
55 | private Scene m_scene; | ||
56 | |||
57 | private IInventoryService m_inventoryService; | ||
58 | |||
59 | private string m_fetchInventory2Url; | ||
60 | |||
61 | private FetchInventory2Handler m_fetchHandler; | ||
62 | |||
63 | #region ISharedRegionModule Members | ||
64 | |||
65 | public void Initialise(IConfigSource source) | ||
66 | { | ||
67 | IConfig config = source.Configs["ClientStack.LindenCaps"]; | ||
68 | if (config == null) | ||
69 | return; | ||
70 | |||
71 | m_fetchInventory2Url = config.GetString("Cap_FetchInventory2", string.Empty); | ||
72 | |||
73 | if (m_fetchInventory2Url != string.Empty) | ||
74 | Enabled = true; | ||
75 | } | ||
76 | |||
77 | public void AddRegion(Scene s) | ||
78 | { | ||
79 | if (!Enabled) | ||
80 | return; | ||
81 | |||
82 | m_scene = s; | ||
83 | } | ||
84 | |||
85 | public void RemoveRegion(Scene s) | ||
86 | { | ||
87 | if (!Enabled) | ||
88 | return; | ||
89 | |||
90 | m_scene.EventManager.OnRegisterCaps -= RegisterCaps; | ||
91 | m_scene = null; | ||
92 | } | ||
93 | |||
94 | public void RegionLoaded(Scene s) | ||
95 | { | ||
96 | if (!Enabled) | ||
97 | return; | ||
98 | |||
99 | m_inventoryService = m_scene.InventoryService; | ||
100 | |||
101 | // We'll reuse the same handler for all requests. | ||
102 | if (m_fetchInventory2Url == "localhost") | ||
103 | m_fetchHandler = new FetchInventory2Handler(m_inventoryService); | ||
104 | |||
105 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; | ||
106 | } | ||
107 | |||
108 | public void PostInitialise() {} | ||
109 | |||
110 | public void Close() {} | ||
111 | |||
112 | public string Name { get { return "FetchInventory2Module"; } } | ||
113 | |||
114 | public Type ReplaceableInterface | ||
115 | { | ||
116 | get { return null; } | ||
117 | } | ||
118 | |||
119 | #endregion | ||
120 | |||
121 | private void RegisterCaps(UUID agentID, Caps caps) | ||
122 | { | ||
123 | RegisterFetchCap(agentID, caps, "FetchInventory2", m_fetchInventory2Url); | ||
124 | } | ||
125 | |||
126 | private void RegisterFetchCap(UUID agentID, Caps caps, string capName, string url) | ||
127 | { | ||
128 | string capUrl; | ||
129 | |||
130 | if (url == "localhost") | ||
131 | { | ||
132 | capUrl = "/CAPS/" + UUID.Random(); | ||
133 | |||
134 | IRequestHandler reqHandler | ||
135 | = new RestStreamHandler("POST", capUrl, m_fetchHandler.FetchInventoryRequest); | ||
136 | |||
137 | caps.RegisterHandler(capName, reqHandler); | ||
138 | } | ||
139 | else | ||
140 | { | ||
141 | capUrl = url; | ||
142 | |||
143 | caps.RegisterHandler(capName, capUrl); | ||
144 | } | ||
145 | |||
146 | // m_log.DebugFormat( | ||
147 | // "[FETCH INVENTORY2 MODULE]: Registered capability {0} at {1} in region {2} for {3}", | ||
148 | // capName, capUrl, m_scene.RegionInfo.RegionName, agentID); | ||
149 | } | ||
150 | } | ||
151 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 3bc8750..466e540 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | |||
@@ -5096,15 +5096,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5096 | return (double)Math.Asin(val); | 5096 | return (double)Math.Asin(val); |
5097 | } | 5097 | } |
5098 | 5098 | ||
5099 | // Xantor 30/apr/2008 | 5099 | // jcochran 5/jan/2012 |
5100 | public LSL_Float llAngleBetween(LSL_Rotation a, LSL_Rotation b) | 5100 | public LSL_Float llAngleBetween(LSL_Rotation a, LSL_Rotation b) |
5101 | { | 5101 | { |
5102 | m_host.AddScriptLPS(1); | 5102 | m_host.AddScriptLPS(1); |
5103 | 5103 | ||
5104 | double angle = Math.Acos(a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s) * 2; | 5104 | double aa = (a.x * a.x + a.y * a.y + a.z * a.z + a.s * a.s); |
5105 | if (angle < 0) angle = -angle; | 5105 | double bb = (b.x * b.x + b.y * b.y + b.z * b.z + b.s * b.s); |
5106 | if (angle > Math.PI) return (Math.PI * 2 - angle); | 5106 | double aa_bb = aa * bb; |
5107 | return angle; | 5107 | if (aa_bb == 0) return 0.0; |
5108 | double ab = (a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s); | ||
5109 | double quotient = (ab * ab) / aa_bb; | ||
5110 | if (quotient >= 1.0) return 0.0; | ||
5111 | return Math.Acos(2 * quotient - 1); | ||
5108 | } | 5112 | } |
5109 | 5113 | ||
5110 | public LSL_String llGetInventoryKey(string name) | 5114 | public LSL_String llGetInventoryKey(string name) |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs index 0cbad41..3baa723 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs | |||
@@ -75,32 +75,49 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
75 | [Test] | 75 | [Test] |
76 | public void TestllAngleBetween() | 76 | public void TestllAngleBetween() |
77 | { | 77 | { |
78 | CheckllAngleBetween(new Vector3(1, 0, 0), 0); | 78 | CheckllAngleBetween(new Vector3(1, 0, 0), 0, 1, 1); |
79 | CheckllAngleBetween(new Vector3(1, 0, 0), 90); | 79 | CheckllAngleBetween(new Vector3(1, 0, 0), 90, 1, 1); |
80 | CheckllAngleBetween(new Vector3(1, 0, 0), 180); | 80 | CheckllAngleBetween(new Vector3(1, 0, 0), 180, 1, 1); |
81 | 81 | ||
82 | CheckllAngleBetween(new Vector3(0, 1, 0), 0); | 82 | CheckllAngleBetween(new Vector3(0, 1, 0), 0, 1, 1); |
83 | CheckllAngleBetween(new Vector3(0, 1, 0), 90); | 83 | CheckllAngleBetween(new Vector3(0, 1, 0), 90, 1, 1); |
84 | CheckllAngleBetween(new Vector3(0, 1, 0), 180); | 84 | CheckllAngleBetween(new Vector3(0, 1, 0), 180, 1, 1); |
85 | 85 | ||
86 | CheckllAngleBetween(new Vector3(0, 0, 1), 0); | 86 | CheckllAngleBetween(new Vector3(0, 0, 1), 0, 1, 1); |
87 | CheckllAngleBetween(new Vector3(0, 0, 1), 90); | 87 | CheckllAngleBetween(new Vector3(0, 0, 1), 90, 1, 1); |
88 | CheckllAngleBetween(new Vector3(0, 0, 1), 180); | 88 | CheckllAngleBetween(new Vector3(0, 0, 1), 180, 1, 1); |
89 | 89 | ||
90 | CheckllAngleBetween(new Vector3(1, 1, 1), 0); | 90 | CheckllAngleBetween(new Vector3(1, 1, 1), 0, 1, 1); |
91 | CheckllAngleBetween(new Vector3(1, 1, 1), 90); | 91 | CheckllAngleBetween(new Vector3(1, 1, 1), 90, 1, 1); |
92 | CheckllAngleBetween(new Vector3(1, 1, 1), 180); | 92 | CheckllAngleBetween(new Vector3(1, 1, 1), 180, 1, 1); |
93 | |||
94 | CheckllAngleBetween(new Vector3(1, 0, 0), 0, 1.6f, 1.8f); | ||
95 | CheckllAngleBetween(new Vector3(1, 0, 0), 90, 0.3f, 3.9f); | ||
96 | CheckllAngleBetween(new Vector3(1, 0, 0), 180, 8.8f, 7.4f); | ||
97 | |||
98 | CheckllAngleBetween(new Vector3(0, 1, 0), 0, 9.8f, -9.4f); | ||
99 | CheckllAngleBetween(new Vector3(0, 1, 0), 90, 8.4f, -8.2f); | ||
100 | CheckllAngleBetween(new Vector3(0, 1, 0), 180, 0.4f, -5.8f); | ||
101 | |||
102 | CheckllAngleBetween(new Vector3(0, 0, 1), 0, -6.8f, 3.4f); | ||
103 | CheckllAngleBetween(new Vector3(0, 0, 1), 90, -3.6f, 5.6f); | ||
104 | CheckllAngleBetween(new Vector3(0, 0, 1), 180, -3.8f, 1.1f); | ||
105 | |||
106 | CheckllAngleBetween(new Vector3(1, 1, 1), 0, -7.7f, -2.0f); | ||
107 | CheckllAngleBetween(new Vector3(1, 1, 1), 90, -3.0f, -9.1f); | ||
108 | CheckllAngleBetween(new Vector3(1, 1, 1), 180, -7.9f, -8.0f); | ||
93 | } | 109 | } |
94 | 110 | ||
95 | private void CheckllAngleBetween(Vector3 axis,float originalAngle) | 111 | private void CheckllAngleBetween(Vector3 axis,float originalAngle, float denorm1, float denorm2) |
96 | { | 112 | { |
97 | Quaternion rotation1 = Quaternion.CreateFromAxisAngle(axis, 0); | 113 | Quaternion rotation1 = Quaternion.CreateFromAxisAngle(axis, 0); |
98 | Quaternion rotation2 = Quaternion.CreateFromAxisAngle(axis, ToRadians(originalAngle)); | 114 | Quaternion rotation2 = Quaternion.CreateFromAxisAngle(axis, ToRadians(originalAngle)); |
115 | rotation1 *= denorm1; | ||
116 | rotation2 *= denorm2; | ||
99 | 117 | ||
100 | double deducedAngle = FromLslFloat(m_lslApi.llAngleBetween(ToLslQuaternion(rotation2), ToLslQuaternion(rotation1))); | 118 | double deducedAngle = FromLslFloat(m_lslApi.llAngleBetween(ToLslQuaternion(rotation2), ToLslQuaternion(rotation1))); |
101 | 119 | ||
102 | Assert.Greater(deducedAngle, ToRadians(originalAngle) - ANGLE_ACCURACY_IN_RADIANS); | 120 | Assert.That(deducedAngle, Is.EqualTo(ToRadians(originalAngle)).Within(ANGLE_ACCURACY_IN_RADIANS), "TestllAngleBetween check fail"); |
103 | Assert.Less(deducedAngle, ToRadians(originalAngle) + ANGLE_ACCURACY_IN_RADIANS); | ||
104 | } | 121 | } |
105 | 122 | ||
106 | #region Conversions to and from LSL_Types | 123 | #region Conversions to and from LSL_Types |
@@ -142,30 +159,97 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
142 | public void TestllRot2Euler() | 159 | public void TestllRot2Euler() |
143 | { | 160 | { |
144 | // 180, 90 and zero degree rotations. | 161 | // 180, 90 and zero degree rotations. |
145 | CheckllRot2Euler(new LSL_Types.Quaternion(1.0f, 0.0f, 0.0f, 0.0f), new LSL_Types.Vector3(Math.PI, 0.0f, 0.0f)); | 162 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, 0.0f, 0.0f, 1.0f)); |
146 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, 1.0f, 0.0f, 0.0f), new LSL_Types.Vector3(Math.PI, 0.0f, Math.PI)); | 163 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, 0.0f, 0.707107f, 0.707107f)); |
147 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, 0.0f, 1.0f, 0.0f), new LSL_Types.Vector3(0.0f, 0.0f, Math.PI)); | 164 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, 0.0f, 1.0f, 0.0f)); |
148 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, 0.0f, 0.0f, 1.0f), new LSL_Types.Vector3(0.0f, 0.0f, 0.0f)); | 165 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, 0.0f, 0.707107f, -0.707107f)); |
149 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.5f, -0.5f, 0.5f, 0.5f), new LSL_Types.Vector3(0, -Math.PI / 2.0f, Math.PI / 2.0f)); | 166 | CheckllRot2Euler(new LSL_Types.Quaternion(0.707107f, 0.0f, 0.0f, 0.707107f)); |
150 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.707107f, 0.0f, 0.0f, -0.707107f), new LSL_Types.Vector3(Math.PI / 2.0f, 0.0f, 0.0f)); | 167 | CheckllRot2Euler(new LSL_Types.Quaternion(0.5f, -0.5f, 0.5f, 0.5f)); |
168 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, -0.707107f, 0.707107f, 0.0f)); | ||
169 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.5f, -0.5f, 0.5f, -0.5f)); | ||
170 | CheckllRot2Euler(new LSL_Types.Quaternion(1.0f, 0.0f, 0.0f, 0.0f)); | ||
171 | CheckllRot2Euler(new LSL_Types.Quaternion(0.707107f, -0.707107f, 0.0f, 0.0f)); | ||
172 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, -1.0f, 0.0f, 0.0f)); | ||
173 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.707107f, -0.707107f, 0.0f, 0.0f)); | ||
174 | CheckllRot2Euler(new LSL_Types.Quaternion(0.707107f, 0.0f, 0.0f, -0.707107f)); | ||
175 | CheckllRot2Euler(new LSL_Types.Quaternion(0.5f, -0.5f, -0.5f, -0.5f)); | ||
176 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, -0.707107f, -0.707107f, 0.0f)); | ||
177 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.5f, -0.5f, -0.5f, 0.5f)); | ||
178 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, -0.707107f, 0.0f, 0.707107f)); | ||
179 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.5f, -0.5f, 0.5f, 0.5f)); | ||
180 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.707107f, 0.0f, 0.707107f, 0.0f)); | ||
181 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.5f, 0.5f, 0.5f, -0.5f)); | ||
182 | CheckllRot2Euler(new LSL_Types.Quaternion(0.0f, -0.707107f, 0.0f, -0.707107f)); | ||
183 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.5f, -0.5f, -0.5f, -0.5f)); | ||
184 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.707107f, 0.0f, -0.707107f, 0.0f)); | ||
185 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.5f, 0.5f, -0.5f, 0.5f)); | ||
186 | |||
151 | // A couple of messy rotations. | 187 | // A couple of messy rotations. |
152 | CheckllRot2Euler(new LSL_Types.Quaternion(1.0f, 5.651f, -3.1f, 67.023f), new LSL_Types.Vector3(0.037818f, 0.166447f, -0.095595f)); | 188 | CheckllRot2Euler(new LSL_Types.Quaternion(1.0f, 5.651f, -3.1f, 67.023f)); |
153 | CheckllRot2Euler(new LSL_Types.Quaternion(0.719188f, -0.408934f, -0.363998f, -0.427841f), new LSL_Types.Vector3(-1.954769f, -0.174533f, 1.151917f)); | 189 | CheckllRot2Euler(new LSL_Types.Quaternion(0.719188f, -0.408934f, -0.363998f, -0.427841f)); |
190 | |||
191 | // Some deliberately malicious rotations (intended on provoking singularity errors) | ||
192 | // The "f" suffexes are deliberately omitted. | ||
193 | CheckllRot2Euler(new LSL_Types.Quaternion(0.50001f, 0.50001f, 0.50001f, 0.50001f)); | ||
194 | // More malice. The "f" suffixes are deliberately omitted. | ||
195 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.701055, 0.092296, 0.701055, -0.092296)); | ||
196 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.183005, -0.683010, 0.183005, 0.683010)); | ||
197 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.430460, -0.560982, 0.430460, 0.560982)); | ||
198 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.701066, 0.092301, -0.701066, 0.092301)); | ||
199 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.183013, -0.683010, 0.183013, 0.683010)); | ||
200 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.183005, -0.683014, -0.183005, -0.683014)); | ||
201 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.353556, 0.612375, 0.353556, -0.612375)); | ||
202 | CheckllRot2Euler(new LSL_Types.Quaternion(0.353554, -0.612385, -0.353554, 0.612385)); | ||
203 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.560989, 0.430450, 0.560989, -0.430450)); | ||
204 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.183013, 0.683009, -0.183013, 0.683009)); | ||
205 | CheckllRot2Euler(new LSL_Types.Quaternion(0.430457, -0.560985, -0.430457, 0.560985)); | ||
206 | CheckllRot2Euler(new LSL_Types.Quaternion(0.353552, 0.612360, -0.353552, -0.612360)); | ||
207 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.499991, 0.500003, 0.499991, -0.500003)); | ||
208 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.353555, -0.612385, -0.353555, -0.612385)); | ||
209 | CheckllRot2Euler(new LSL_Types.Quaternion(0.701066, -0.092301, -0.701066, 0.092301)); | ||
210 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.499991, 0.500007, 0.499991, -0.500007)); | ||
211 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.683002, 0.183016, -0.683002, 0.183016)); | ||
212 | CheckllRot2Euler(new LSL_Types.Quaternion(0.430458, 0.560982, 0.430458, 0.560982)); | ||
213 | CheckllRot2Euler(new LSL_Types.Quaternion(0.499991, -0.500003, -0.499991, 0.500003)); | ||
214 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.183009, 0.683011, -0.183009, 0.683011)); | ||
215 | CheckllRot2Euler(new LSL_Types.Quaternion(0.560975, -0.430457, 0.560975, -0.430457)); | ||
216 | CheckllRot2Euler(new LSL_Types.Quaternion(0.701055, 0.092300, 0.701055, 0.092300)); | ||
217 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.560990, 0.430459, -0.560990, 0.430459)); | ||
218 | CheckllRot2Euler(new LSL_Types.Quaternion(-0.092302, -0.701059, -0.092302, -0.701059)); | ||
154 | } | 219 | } |
155 | 220 | ||
156 | private void CheckllRot2Euler(LSL_Types.Quaternion rot, LSL_Types.Vector3 eulerCheck) | 221 | /// <summary> |
222 | /// Check an llRot2Euler conversion. | ||
223 | /// </summary> | ||
224 | /// <remarks> | ||
225 | /// Testing Rot2Euler this way instead of comparing against expected angles because | ||
226 | /// 1. There are several ways to get to the original Quaternion. For example a rotation | ||
227 | /// of PI and -PI will give the same result. But PI and -PI aren't equal. | ||
228 | /// 2. This method checks to see if the calculated angles from a quaternion can be used | ||
229 | /// to create a new quaternion to produce the same rotation. | ||
230 | /// However, can't compare the newly calculated quaternion against the original because | ||
231 | /// once again, there are multiple quaternions that give the same result. For instance | ||
232 | /// <X, Y, Z, S> == <-X, -Y, -Z, -S>. Additionally, the magnitude of S can be changed | ||
233 | /// and will still result in the same rotation if the values for X, Y, Z are also changed | ||
234 | /// to compensate. | ||
235 | /// However, if two quaternions represent the same rotation, then multiplying the first | ||
236 | /// quaternion by the conjugate of the second, will give a third quaternion representing | ||
237 | /// a zero rotation. This can be tested for by looking at the X, Y, Z values which should | ||
238 | /// be zero. | ||
239 | /// </remarks> | ||
240 | /// <param name="rot"></param> | ||
241 | private void CheckllRot2Euler(LSL_Types.Quaternion rot) | ||
157 | { | 242 | { |
158 | // Call LSL function to convert quaternion rotaion to euler radians. | 243 | // Call LSL function to convert quaternion rotaion to euler radians. |
159 | LSL_Types.Vector3 eulerCalc = m_lslApi.llRot2Euler(rot); | 244 | LSL_Types.Vector3 eulerCalc = m_lslApi.llRot2Euler(rot); |
160 | // Check upper and lower bounds of x, y and z. | 245 | // Now use the euler radians to recalculate a new quaternion rotation |
161 | // This type of check is performed as opposed to comparing for equal numbers, in order to allow slight | 246 | LSL_Types.Quaternion newRot = m_lslApi.llEuler2Rot(eulerCalc); |
162 | // differences in accuracy. | 247 | // Multiple original quaternion by conjugate of quaternion calculated with angles. |
163 | Assert.Greater(eulerCalc.x, eulerCheck.x - ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler X lower bounds check fail"); | 248 | LSL_Types.Quaternion check = rot * new LSL_Types.Quaternion(-newRot.x, -newRot.y, -newRot.z, newRot.s); |
164 | Assert.Less(eulerCalc.x, eulerCheck.x + ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler X upper bounds check fail"); | 249 | |
165 | Assert.Greater(eulerCalc.y, eulerCheck.y - ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler Y lower bounds check fail"); | 250 | Assert.AreEqual(0.0, check.x, VECTOR_COMPONENT_ACCURACY, "TestllRot2Euler X bounds check fail"); |
166 | Assert.Less(eulerCalc.y, eulerCheck.y + ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler Y upper bounds check fail"); | 251 | Assert.AreEqual(0.0, check.y, VECTOR_COMPONENT_ACCURACY, "TestllRot2Euler Y bounds check fail"); |
167 | Assert.Greater(eulerCalc.z, eulerCheck.z - ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler Z lower bounds check fail"); | 252 | Assert.AreEqual(0.0, check.z, VECTOR_COMPONENT_ACCURACY, "TestllRot2Euler Z bounds check fail"); |
168 | Assert.Less(eulerCalc.z, eulerCheck.z + ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler Z upper bounds check fail"); | ||
169 | } | 253 | } |
170 | 254 | ||
171 | [Test] | 255 | [Test] |
diff --git a/bin/OpenSimDefaults.ini b/bin/OpenSimDefaults.ini index d2345ba..6995410 100644 --- a/bin/OpenSimDefaults.ini +++ b/bin/OpenSimDefaults.ini | |||
@@ -515,13 +515,13 @@ | |||
515 | ;DisableFacelights = "false(1815) | 515 | ;DisableFacelights = "false(1815) |
516 | 516 | ||
517 | [ClientStack.LindenCaps] | 517 | [ClientStack.LindenCaps] |
518 | ;; Long list of capabilities taken from | 518 | ;; Long list of capabilities taken from |
519 | ;; http://wiki.secondlife.com/wiki/Current_Sim_Capabilities | 519 | ;; http://wiki.secondlife.com/wiki/Current_Sim_Capabilities |
520 | ;; Not all are supported by OpenSim. The ones supported are | 520 | ;; Not all are supported by OpenSim. The ones supported are |
521 | ;; set to localhost. These defaults can be overwritten | 521 | ;; set to localhost. These defaults can be overwritten |
522 | ;; in OpenSim.ini | 522 | ;; in OpenSim.ini |
523 | ;; | 523 | ;; |
524 | Cap_AttachmentResources = "" | 524 | Cap_AttachmentResources = "" |
525 | Cap_AvatarPickerSearch = "" | 525 | Cap_AvatarPickerSearch = "" |
526 | Cap_ChatSessionRequest = "" | 526 | Cap_ChatSessionRequest = "" |
527 | Cap_CopyInventoryFromNotecard = "" | 527 | Cap_CopyInventoryFromNotecard = "" |
@@ -579,12 +579,13 @@ | |||
579 | Cap_ViewerStartAuction = "" | 579 | Cap_ViewerStartAuction = "" |
580 | Cap_ViewerStats = "" | 580 | Cap_ViewerStats = "" |
581 | 581 | ||
582 | ; The fetch inventory descendents caps are supported by OpenSim, but may | 582 | ; The various fetch inventory caps are supported by OpenSim, but may |
583 | ; lead to poor sim performance if served by the simulators, | 583 | ; lead to poor sim performance if served by the simulators, |
584 | ; so they are disabled by default. | 584 | ; so they are currently disabled by default. |
585 | ; FetchInventoryDescendents2 is the one used in the latest Linden Lab viewers (from some point in the v2 series and above) | 585 | ; FetchInventoryDescendents2 and FetchInventory2 are the ones used in the latest Linden Lab viewers (from some point in the v2 series and above) |
586 | Cap_WebFetchInventoryDescendents = "" | 586 | Cap_WebFetchInventoryDescendents = "" |
587 | Cap_FetchInventoryDescendents2 = "" | 587 | Cap_FetchInventoryDescendents2 = "" |
588 | Cap_FetchInventory2 = "" | ||
588 | 589 | ||
589 | 590 | ||
590 | [Chat] | 591 | [Chat] |