diff options
author | Melanie | 2012-09-24 20:14:00 +0100 |
---|---|---|
committer | Melanie | 2012-09-24 20:14:00 +0100 |
commit | bbaf2c5a80441fdbd2f55e02ec9f46c3b66869c6 (patch) | |
tree | 2ac67907f6333bbbc9e4d821c6607b53d0e22acb /OpenSim/Region/CoreModules | |
parent | Merge branch 'master' into careminster (diff) | |
parent | HG Rez object: warn the user if the item or asset cannot be found. (diff) | |
download | opensim-SC_OLD-bbaf2c5a80441fdbd2f55e02ec9f46c3b66869c6.zip opensim-SC_OLD-bbaf2c5a80441fdbd2f55e02ec9f46c3b66869c6.tar.gz opensim-SC_OLD-bbaf2c5a80441fdbd2f55e02ec9f46c3b66869c6.tar.bz2 opensim-SC_OLD-bbaf2c5a80441fdbd2f55e02ec9f46c3b66869c6.tar.xz |
Merge branch 'master' into careminster
Conflicts:
OpenSim/Region/Framework/Scenes/Scene.cs
Diffstat (limited to 'OpenSim/Region/CoreModules')
10 files changed, 468 insertions, 115 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index 951afd7..5d41c1c 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs | |||
@@ -933,6 +933,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
933 | 933 | ||
934 | InventoryItemBase item = new InventoryItemBase(itemID, sp.UUID); | 934 | InventoryItemBase item = new InventoryItemBase(itemID, sp.UUID); |
935 | item = m_scene.InventoryService.GetItem(item); | 935 | item = m_scene.InventoryService.GetItem(item); |
936 | if (item == null) | ||
937 | return; | ||
938 | |||
936 | bool changed = sp.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID); | 939 | bool changed = sp.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID); |
937 | if (changed && m_scene.AvatarFactory != null) | 940 | if (changed && m_scene.AvatarFactory != null) |
938 | { | 941 | { |
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs index 48f3a23..b7a1169 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs | |||
@@ -62,7 +62,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
62 | public class AttachmentsModuleTests : OpenSimTestCase | 62 | public class AttachmentsModuleTests : OpenSimTestCase |
63 | { | 63 | { |
64 | private AutoResetEvent m_chatEvent = new AutoResetEvent(false); | 64 | private AutoResetEvent m_chatEvent = new AutoResetEvent(false); |
65 | private OSChatMessage m_osChatMessageReceived; | 65 | // private OSChatMessage m_osChatMessageReceived; |
66 | 66 | ||
67 | [TestFixtureSetUp] | 67 | [TestFixtureSetUp] |
68 | public void FixtureInit() | 68 | public void FixtureInit() |
@@ -83,7 +83,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
83 | { | 83 | { |
84 | // Console.WriteLine("Got chat [{0}]", oscm.Message); | 84 | // Console.WriteLine("Got chat [{0}]", oscm.Message); |
85 | 85 | ||
86 | m_osChatMessageReceived = oscm; | 86 | // m_osChatMessageReceived = oscm; |
87 | m_chatEvent.Set(); | 87 | m_chatEvent.Set(); |
88 | } | 88 | } |
89 | 89 | ||
diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs index 4c786ff..a1d8d5a 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs | |||
@@ -150,6 +150,34 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
150 | 150 | ||
151 | if (m_Enabled) | 151 | if (m_Enabled) |
152 | scene.RegisterModuleInterface<IUserAgentVerificationModule>(this); | 152 | scene.RegisterModuleInterface<IUserAgentVerificationModule>(this); |
153 | |||
154 | scene.EventManager.OnIncomingSceneObject += OnIncomingSceneObject; | ||
155 | } | ||
156 | |||
157 | void OnIncomingSceneObject(SceneObjectGroup so) | ||
158 | { | ||
159 | if (!so.IsAttachment) | ||
160 | return; | ||
161 | |||
162 | if (so.Scene.UserManagementModule.IsLocalGridUser(so.AttachedAvatar)) | ||
163 | return; | ||
164 | |||
165 | // foreign user | ||
166 | AgentCircuitData aCircuit = so.Scene.AuthenticateHandler.GetAgentCircuitData(so.AttachedAvatar); | ||
167 | if (aCircuit != null && (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0) | ||
168 | { | ||
169 | if (aCircuit.ServiceURLs != null && aCircuit.ServiceURLs.ContainsKey("AssetServerURI")) | ||
170 | { | ||
171 | string url = aCircuit.ServiceURLs["AssetServerURI"].ToString(); | ||
172 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Incoming attachement {0} for HG user {1} with asset server {2}", so.Name, so.AttachedAvatar, url); | ||
173 | Dictionary<UUID, AssetType> ids = new Dictionary<UUID, AssetType>(); | ||
174 | HGUuidGatherer uuidGatherer = new HGUuidGatherer(so.Scene.AssetService, url); | ||
175 | uuidGatherer.GatherAssetUuids(so, ids); | ||
176 | |||
177 | foreach (KeyValuePair<UUID, AssetType> kvp in ids) | ||
178 | uuidGatherer.FetchAsset(kvp.Key); | ||
179 | } | ||
180 | } | ||
153 | } | 181 | } |
154 | 182 | ||
155 | protected override void OnNewClient(IClientAPI client) | 183 | protected override void OnNewClient(IClientAPI client) |
diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs index eaadc1b..6f62856 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs | |||
@@ -71,19 +71,19 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
71 | 71 | ||
72 | #region Internal functions | 72 | #region Internal functions |
73 | 73 | ||
74 | public AssetBase FetchAsset(string url, UUID assetID) | 74 | public AssetMetadata FetchMetadata(string url, UUID assetID) |
75 | { | 75 | { |
76 | if (!url.EndsWith("/") && !url.EndsWith("=")) | 76 | if (!url.EndsWith("/") && !url.EndsWith("=")) |
77 | url = url + "/"; | 77 | url = url + "/"; |
78 | 78 | ||
79 | AssetBase asset = m_scene.AssetService.Get(url + assetID.ToString()); | 79 | AssetMetadata meta = m_scene.AssetService.GetMetadata(url + assetID.ToString()); |
80 | 80 | ||
81 | if (asset != null) | 81 | if (meta != null) |
82 | { | 82 | m_log.DebugFormat("[HG ASSET MAPPER]: Fetched metadata for asset {0} of type {1} from {2} ", assetID, meta.Type, url); |
83 | m_log.DebugFormat("[HG ASSET MAPPER]: Copied asset {0} from {1} to local asset server. ", asset.ID, url); | 83 | else |
84 | return asset; | 84 | m_log.DebugFormat("[HG ASSET MAPPER]: Unable to fetched metadata for asset {0} from {1} ", assetID, url); |
85 | } | 85 | |
86 | return null; | 86 | return meta; |
87 | } | 87 | } |
88 | 88 | ||
89 | public bool PostAsset(string url, AssetBase asset) | 89 | public bool PostAsset(string url, AssetBase asset) |
@@ -93,6 +93,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
93 | if (!url.EndsWith("/") && !url.EndsWith("=")) | 93 | if (!url.EndsWith("/") && !url.EndsWith("=")) |
94 | url = url + "/"; | 94 | url = url + "/"; |
95 | 95 | ||
96 | bool success = true; | ||
96 | // See long comment in AssetCache.AddAsset | 97 | // See long comment in AssetCache.AddAsset |
97 | if (!asset.Temporary || asset.Local) | 98 | if (!asset.Temporary || asset.Local) |
98 | { | 99 | { |
@@ -103,14 +104,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
103 | // not having a global naming infrastructure | 104 | // not having a global naming infrastructure |
104 | AssetBase asset1 = new AssetBase(asset.FullID, asset.Name, asset.Type, asset.Metadata.CreatorID); | 105 | AssetBase asset1 = new AssetBase(asset.FullID, asset.Name, asset.Type, asset.Metadata.CreatorID); |
105 | Copy(asset, asset1); | 106 | Copy(asset, asset1); |
106 | try | 107 | asset1.ID = url + asset.ID; |
107 | { | ||
108 | asset1.ID = url + asset.ID; | ||
109 | } | ||
110 | catch | ||
111 | { | ||
112 | m_log.Warn("[HG ASSET MAPPER]: Oops."); | ||
113 | } | ||
114 | 108 | ||
115 | AdjustIdentifiers(asset1.Metadata); | 109 | AdjustIdentifiers(asset1.Metadata); |
116 | if (asset1.Metadata.Type == (sbyte)AssetType.Object) | 110 | if (asset1.Metadata.Type == (sbyte)AssetType.Object) |
@@ -118,11 +112,17 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
118 | else | 112 | else |
119 | asset1.Data = asset.Data; | 113 | asset1.Data = asset.Data; |
120 | 114 | ||
121 | m_scene.AssetService.Store(asset1); | 115 | string id = m_scene.AssetService.Store(asset1); |
122 | m_log.DebugFormat("[HG ASSET MAPPER]: Posted copy of asset {0} from local asset server to {1}", asset1.ID, url); | 116 | if (id == string.Empty) |
117 | { | ||
118 | m_log.DebugFormat("[HG ASSET MAPPER]: Asset server {0} did not accept {1}", url, asset.ID); | ||
119 | success = false; | ||
120 | } | ||
121 | else | ||
122 | m_log.DebugFormat("[HG ASSET MAPPER]: Posted copy of asset {0} from local asset server to {1}", asset1.ID, url); | ||
123 | } | 123 | } |
124 | return true; | 124 | return success; |
125 | } | 125 | } |
126 | else | 126 | else |
127 | m_log.Warn("[HG ASSET MAPPER]: Tried to post asset to remote server, but asset not in local cache."); | 127 | m_log.Warn("[HG ASSET MAPPER]: Tried to post asset to remote server, but asset not in local cache."); |
128 | 128 | ||
@@ -222,28 +222,19 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
222 | 222 | ||
223 | public void Get(UUID assetID, UUID ownerID, string userAssetURL) | 223 | public void Get(UUID assetID, UUID ownerID, string userAssetURL) |
224 | { | 224 | { |
225 | // Get the item from the remote asset server onto the local AssetCache | 225 | // Get the item from the remote asset server onto the local AssetService |
226 | // and place an entry in m_assetMap | ||
227 | 226 | ||
228 | m_log.Debug("[HG ASSET MAPPER]: Fetching object " + assetID + " from asset server " + userAssetURL); | 227 | AssetMetadata meta = FetchMetadata(userAssetURL, assetID); |
229 | AssetBase asset = FetchAsset(userAssetURL, assetID); | 228 | if (meta == null) |
229 | return; | ||
230 | 230 | ||
231 | if (asset != null) | 231 | // The act of gathering UUIDs downloads the assets from the remote server |
232 | { | 232 | Dictionary<UUID, AssetType> ids = new Dictionary<UUID, AssetType>(); |
233 | // OK, now fetch the inside. | 233 | HGUuidGatherer uuidGatherer = new HGUuidGatherer(m_scene.AssetService, userAssetURL); |
234 | Dictionary<UUID, AssetType> ids = new Dictionary<UUID, AssetType>(); | 234 | uuidGatherer.GatherAssetUuids(assetID, (AssetType)meta.Type, ids); |
235 | HGUuidGatherer uuidGatherer = new HGUuidGatherer(this, m_scene.AssetService, userAssetURL); | ||
236 | uuidGatherer.GatherAssetUuids(asset.FullID, (AssetType)asset.Type, ids); | ||
237 | if (ids.ContainsKey(assetID)) | ||
238 | ids.Remove(assetID); | ||
239 | foreach (UUID uuid in ids.Keys) | ||
240 | FetchAsset(userAssetURL, uuid); | ||
241 | 235 | ||
242 | m_log.DebugFormat("[HG ASSET MAPPER]: Successfully fetched asset {0} from asset server {1}", asset.ID, userAssetURL); | 236 | m_log.DebugFormat("[HG ASSET MAPPER]: Successfully fetched asset {0} from asset server {1}", assetID, userAssetURL); |
243 | 237 | ||
244 | } | ||
245 | else | ||
246 | m_log.Warn("[HG ASSET MAPPER]: Could not fetch asset from remote asset server " + userAssetURL); | ||
247 | } | 238 | } |
248 | 239 | ||
249 | 240 | ||
@@ -257,19 +248,23 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
257 | if (asset != null) | 248 | if (asset != null) |
258 | { | 249 | { |
259 | Dictionary<UUID, AssetType> ids = new Dictionary<UUID, AssetType>(); | 250 | Dictionary<UUID, AssetType> ids = new Dictionary<UUID, AssetType>(); |
260 | HGUuidGatherer uuidGatherer = new HGUuidGatherer(this, m_scene.AssetService, string.Empty); | 251 | HGUuidGatherer uuidGatherer = new HGUuidGatherer(m_scene.AssetService, string.Empty); |
261 | uuidGatherer.GatherAssetUuids(asset.FullID, (AssetType)asset.Type, ids); | 252 | uuidGatherer.GatherAssetUuids(asset.FullID, (AssetType)asset.Type, ids); |
253 | bool success = false; | ||
262 | foreach (UUID uuid in ids.Keys) | 254 | foreach (UUID uuid in ids.Keys) |
263 | { | 255 | { |
264 | asset = m_scene.AssetService.Get(uuid.ToString()); | 256 | asset = m_scene.AssetService.Get(uuid.ToString()); |
265 | if (asset == null) | 257 | if (asset == null) |
266 | m_log.DebugFormat("[HG ASSET MAPPER]: Could not find asset {0}", uuid); | 258 | m_log.DebugFormat("[HG ASSET MAPPER]: Could not find asset {0}", uuid); |
267 | else | 259 | else |
268 | PostAsset(userAssetURL, asset); | 260 | success = PostAsset(userAssetURL, asset); |
269 | } | 261 | } |
270 | 262 | ||
271 | // maybe all pieces got there... | 263 | // maybe all pieces got there... |
272 | m_log.DebugFormat("[HG ASSET MAPPER]: Successfully posted item {0} to asset server {1}", assetID, userAssetURL); | 264 | if (!success) |
265 | m_log.DebugFormat("[HG ASSET MAPPER]: Problems posting item {0} to asset server {1}", assetID, userAssetURL); | ||
266 | else | ||
267 | m_log.DebugFormat("[HG ASSET MAPPER]: Successfully posted item {0} to asset server {1}", assetID, userAssetURL); | ||
273 | 268 | ||
274 | } | 269 | } |
275 | else | 270 | else |
diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs index a0cad40..80257bd 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs | |||
@@ -263,8 +263,13 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
263 | //} | 263 | //} |
264 | 264 | ||
265 | // OK, we're done fetching. Pass it up to the default RezObject | 265 | // OK, we're done fetching. Pass it up to the default RezObject |
266 | return base.RezObject(remoteClient, itemID, RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection, | 266 | SceneObjectGroup sog = base.RezObject(remoteClient, itemID, RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection, |
267 | RezSelected, RemoveItem, fromTaskID, attachment); | 267 | RezSelected, RemoveItem, fromTaskID, attachment); |
268 | |||
269 | if (sog == null) | ||
270 | remoteClient.SendAgentAlertMessage("Unable to rez: problem accessing inventory or locating assets", false); | ||
271 | |||
272 | return sog; | ||
268 | 273 | ||
269 | } | 274 | } |
270 | 275 | ||
diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGUuidGatherer.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGUuidGatherer.cs deleted file mode 100644 index fcb544f..0000000 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGUuidGatherer.cs +++ /dev/null | |||
@@ -1,57 +0,0 @@ | |||
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.Generic; | ||
30 | |||
31 | using OpenSim.Framework; | ||
32 | using OpenSim.Region.Framework.Scenes; | ||
33 | using OpenSim.Services.Interfaces; | ||
34 | using OpenMetaverse; | ||
35 | |||
36 | namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | ||
37 | { | ||
38 | public class HGUuidGatherer : UuidGatherer | ||
39 | { | ||
40 | protected string m_assetServerURL; | ||
41 | protected HGAssetMapper m_assetMapper; | ||
42 | |||
43 | public HGUuidGatherer(HGAssetMapper assMap, IAssetService assetCache, string assetServerURL) : base(assetCache) | ||
44 | { | ||
45 | m_assetMapper = assMap; | ||
46 | m_assetServerURL = assetServerURL; | ||
47 | } | ||
48 | |||
49 | protected override AssetBase GetAsset(UUID uuid) | ||
50 | { | ||
51 | if (string.Empty == m_assetServerURL) | ||
52 | return m_assetCache.Get(uuid.ToString()); | ||
53 | else | ||
54 | return m_assetMapper.FetchAsset(m_assetServerURL, uuid); | ||
55 | } | ||
56 | } | ||
57 | } | ||
diff --git a/OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs new file mode 100644 index 0000000..98396ff --- /dev/null +++ b/OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | |||
@@ -0,0 +1,367 @@ | |||
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.Generic; | ||
31 | using Nini.Config; | ||
32 | using log4net; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Region.Framework.Interfaces; | ||
35 | using OpenSim.Region.Framework.Scenes; | ||
36 | using Mono.Addins; | ||
37 | using OpenMetaverse; | ||
38 | using System.Linq; | ||
39 | using System.Linq.Expressions; | ||
40 | |||
41 | namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms | ||
42 | { | ||
43 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ScriptModuleCommsModule")] | ||
44 | class ScriptModuleCommsModule : INonSharedRegionModule, IScriptModuleComms | ||
45 | { | ||
46 | private static readonly ILog m_log = | ||
47 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private Dictionary<string,object> m_constants = new Dictionary<string,object>(); | ||
50 | |||
51 | #region ScriptInvocation | ||
52 | protected class ScriptInvocationData | ||
53 | { | ||
54 | public Delegate ScriptInvocationDelegate { get; private set; } | ||
55 | public string FunctionName { get; private set; } | ||
56 | public Type[] TypeSignature { get; private set; } | ||
57 | public Type ReturnType { get; private set; } | ||
58 | |||
59 | public ScriptInvocationData(string fname, Delegate fn, Type[] callsig, Type returnsig) | ||
60 | { | ||
61 | FunctionName = fname; | ||
62 | ScriptInvocationDelegate = fn; | ||
63 | TypeSignature = callsig; | ||
64 | ReturnType = returnsig; | ||
65 | } | ||
66 | } | ||
67 | |||
68 | private Dictionary<string,ScriptInvocationData> m_scriptInvocation = new Dictionary<string,ScriptInvocationData>(); | ||
69 | #endregion | ||
70 | |||
71 | private IScriptModule m_scriptModule = null; | ||
72 | public event ScriptCommand OnScriptCommand; | ||
73 | |||
74 | #region RegionModuleInterface | ||
75 | public void Initialise(IConfigSource config) | ||
76 | { | ||
77 | } | ||
78 | |||
79 | public void AddRegion(Scene scene) | ||
80 | { | ||
81 | scene.RegisterModuleInterface<IScriptModuleComms>(this); | ||
82 | } | ||
83 | |||
84 | public void RemoveRegion(Scene scene) | ||
85 | { | ||
86 | } | ||
87 | |||
88 | public void RegionLoaded(Scene scene) | ||
89 | { | ||
90 | m_scriptModule = scene.RequestModuleInterface<IScriptModule>(); | ||
91 | |||
92 | if (m_scriptModule != null) | ||
93 | m_log.Info("[MODULE COMMANDS]: Script engine found, module active"); | ||
94 | } | ||
95 | |||
96 | public string Name | ||
97 | { | ||
98 | get { return "ScriptModuleCommsModule"; } | ||
99 | } | ||
100 | |||
101 | public Type ReplaceableInterface | ||
102 | { | ||
103 | get { return null; } | ||
104 | } | ||
105 | |||
106 | public void Close() | ||
107 | { | ||
108 | } | ||
109 | #endregion | ||
110 | |||
111 | #region ScriptModuleComms | ||
112 | |||
113 | public void RaiseEvent(UUID script, string id, string module, string command, string k) | ||
114 | { | ||
115 | ScriptCommand c = OnScriptCommand; | ||
116 | |||
117 | if (c == null) | ||
118 | return; | ||
119 | |||
120 | c(script, id, module, command, k); | ||
121 | } | ||
122 | |||
123 | public void DispatchReply(UUID script, int code, string text, string k) | ||
124 | { | ||
125 | if (m_scriptModule == null) | ||
126 | return; | ||
127 | |||
128 | Object[] args = new Object[] {-1, code, text, k}; | ||
129 | |||
130 | m_scriptModule.PostScriptEvent(script, "link_message", args); | ||
131 | } | ||
132 | |||
133 | private static MethodInfo GetMethodInfoFromType(Type target, string meth, bool searchInstanceMethods) | ||
134 | { | ||
135 | BindingFlags getMethodFlags = | ||
136 | BindingFlags.NonPublic | BindingFlags.Public; | ||
137 | |||
138 | if (searchInstanceMethods) | ||
139 | getMethodFlags |= BindingFlags.Instance; | ||
140 | else | ||
141 | getMethodFlags |= BindingFlags.Static; | ||
142 | |||
143 | return target.GetMethod(meth, getMethodFlags); | ||
144 | } | ||
145 | |||
146 | public void RegisterScriptInvocation(object target, string meth) | ||
147 | { | ||
148 | MethodInfo mi = GetMethodInfoFromType(target.GetType(), meth, true); | ||
149 | if (mi == null) | ||
150 | { | ||
151 | m_log.WarnFormat("[MODULE COMMANDS] Failed to register method {0}", meth); | ||
152 | return; | ||
153 | } | ||
154 | |||
155 | RegisterScriptInvocation(target, mi); | ||
156 | } | ||
157 | |||
158 | public void RegisterScriptInvocation(object target, string[] meth) | ||
159 | { | ||
160 | foreach (string m in meth) | ||
161 | RegisterScriptInvocation(target, m); | ||
162 | } | ||
163 | |||
164 | public void RegisterScriptInvocation(object target, MethodInfo mi) | ||
165 | { | ||
166 | m_log.DebugFormat("[MODULE COMMANDS] Register method {0} from type {1}", mi.Name, (target is Type) ? ((Type)target).Name : target.GetType().Name); | ||
167 | |||
168 | Type delegateType; | ||
169 | List<Type> typeArgs = mi.GetParameters() | ||
170 | .Select(p => p.ParameterType) | ||
171 | .ToList(); | ||
172 | |||
173 | if (mi.ReturnType == typeof(void)) | ||
174 | { | ||
175 | delegateType = Expression.GetActionType(typeArgs.ToArray()); | ||
176 | } | ||
177 | else | ||
178 | { | ||
179 | typeArgs.Add(mi.ReturnType); | ||
180 | delegateType = Expression.GetFuncType(typeArgs.ToArray()); | ||
181 | } | ||
182 | |||
183 | Delegate fcall; | ||
184 | if (!(target is Type)) | ||
185 | fcall = Delegate.CreateDelegate(delegateType, target, mi); | ||
186 | else | ||
187 | fcall = Delegate.CreateDelegate(delegateType, (Type)target, mi.Name); | ||
188 | |||
189 | lock (m_scriptInvocation) | ||
190 | { | ||
191 | ParameterInfo[] parameters = fcall.Method.GetParameters(); | ||
192 | if (parameters.Length < 2) // Must have two UUID params | ||
193 | return; | ||
194 | |||
195 | // Hide the first two parameters | ||
196 | Type[] parmTypes = new Type[parameters.Length - 2]; | ||
197 | for (int i = 2; i < parameters.Length; i++) | ||
198 | parmTypes[i - 2] = parameters[i].ParameterType; | ||
199 | m_scriptInvocation[fcall.Method.Name] = new ScriptInvocationData(fcall.Method.Name, fcall, parmTypes, fcall.Method.ReturnType); | ||
200 | } | ||
201 | } | ||
202 | |||
203 | public void RegisterScriptInvocation(Type target, string[] methods) | ||
204 | { | ||
205 | foreach (string method in methods) | ||
206 | { | ||
207 | MethodInfo mi = GetMethodInfoFromType(target, method, false); | ||
208 | if (mi == null) | ||
209 | m_log.WarnFormat("[MODULE COMMANDS] Failed to register method {0}", method); | ||
210 | else | ||
211 | RegisterScriptInvocation(target, mi); | ||
212 | } | ||
213 | } | ||
214 | |||
215 | public void RegisterScriptInvocations(IRegionModuleBase target) | ||
216 | { | ||
217 | foreach(MethodInfo method in target.GetType().GetMethods( | ||
218 | BindingFlags.Public | BindingFlags.Instance | | ||
219 | BindingFlags.Static)) | ||
220 | { | ||
221 | if(method.GetCustomAttributes( | ||
222 | typeof(ScriptInvocationAttribute), true).Any()) | ||
223 | { | ||
224 | if(method.IsStatic) | ||
225 | RegisterScriptInvocation(target.GetType(), method); | ||
226 | else | ||
227 | RegisterScriptInvocation(target, method); | ||
228 | } | ||
229 | } | ||
230 | } | ||
231 | |||
232 | public Delegate[] GetScriptInvocationList() | ||
233 | { | ||
234 | List<Delegate> ret = new List<Delegate>(); | ||
235 | |||
236 | lock (m_scriptInvocation) | ||
237 | { | ||
238 | foreach (ScriptInvocationData d in m_scriptInvocation.Values) | ||
239 | ret.Add(d.ScriptInvocationDelegate); | ||
240 | } | ||
241 | return ret.ToArray(); | ||
242 | } | ||
243 | |||
244 | public string LookupModInvocation(string fname) | ||
245 | { | ||
246 | lock (m_scriptInvocation) | ||
247 | { | ||
248 | ScriptInvocationData sid; | ||
249 | if (m_scriptInvocation.TryGetValue(fname,out sid)) | ||
250 | { | ||
251 | if (sid.ReturnType == typeof(string)) | ||
252 | return "modInvokeS"; | ||
253 | else if (sid.ReturnType == typeof(int)) | ||
254 | return "modInvokeI"; | ||
255 | else if (sid.ReturnType == typeof(float)) | ||
256 | return "modInvokeF"; | ||
257 | else if (sid.ReturnType == typeof(UUID)) | ||
258 | return "modInvokeK"; | ||
259 | else if (sid.ReturnType == typeof(OpenMetaverse.Vector3)) | ||
260 | return "modInvokeV"; | ||
261 | else if (sid.ReturnType == typeof(OpenMetaverse.Quaternion)) | ||
262 | return "modInvokeR"; | ||
263 | else if (sid.ReturnType == typeof(object[])) | ||
264 | return "modInvokeL"; | ||
265 | |||
266 | m_log.WarnFormat("[MODULE COMMANDS] failed to find match for {0} with return type {1}",fname,sid.ReturnType.Name); | ||
267 | } | ||
268 | } | ||
269 | |||
270 | return null; | ||
271 | } | ||
272 | |||
273 | public Delegate LookupScriptInvocation(string fname) | ||
274 | { | ||
275 | lock (m_scriptInvocation) | ||
276 | { | ||
277 | ScriptInvocationData sid; | ||
278 | if (m_scriptInvocation.TryGetValue(fname,out sid)) | ||
279 | return sid.ScriptInvocationDelegate; | ||
280 | } | ||
281 | |||
282 | return null; | ||
283 | } | ||
284 | |||
285 | public Type[] LookupTypeSignature(string fname) | ||
286 | { | ||
287 | lock (m_scriptInvocation) | ||
288 | { | ||
289 | ScriptInvocationData sid; | ||
290 | if (m_scriptInvocation.TryGetValue(fname,out sid)) | ||
291 | return sid.TypeSignature; | ||
292 | } | ||
293 | |||
294 | return null; | ||
295 | } | ||
296 | |||
297 | public Type LookupReturnType(string fname) | ||
298 | { | ||
299 | lock (m_scriptInvocation) | ||
300 | { | ||
301 | ScriptInvocationData sid; | ||
302 | if (m_scriptInvocation.TryGetValue(fname,out sid)) | ||
303 | return sid.ReturnType; | ||
304 | } | ||
305 | |||
306 | return null; | ||
307 | } | ||
308 | |||
309 | public object InvokeOperation(UUID hostid, UUID scriptid, string fname, params object[] parms) | ||
310 | { | ||
311 | List<object> olist = new List<object>(); | ||
312 | olist.Add(hostid); | ||
313 | olist.Add(scriptid); | ||
314 | foreach (object o in parms) | ||
315 | olist.Add(o); | ||
316 | Delegate fn = LookupScriptInvocation(fname); | ||
317 | return fn.DynamicInvoke(olist.ToArray()); | ||
318 | } | ||
319 | |||
320 | /// <summary> | ||
321 | /// Operation to for a region module to register a constant to be used | ||
322 | /// by the script engine | ||
323 | /// </summary> | ||
324 | public void RegisterConstant(string cname, object value) | ||
325 | { | ||
326 | m_log.DebugFormat("[MODULE COMMANDS] register constant <{0}> with value {1}",cname,value.ToString()); | ||
327 | lock (m_constants) | ||
328 | { | ||
329 | m_constants.Add(cname,value); | ||
330 | } | ||
331 | } | ||
332 | |||
333 | public void RegisterConstants(IRegionModuleBase target) | ||
334 | { | ||
335 | foreach (FieldInfo field in target.GetType().GetFields( | ||
336 | BindingFlags.Public | BindingFlags.Static | | ||
337 | BindingFlags.Instance)) | ||
338 | { | ||
339 | if (field.GetCustomAttributes( | ||
340 | typeof(ScriptConstantAttribute), true).Any()) | ||
341 | { | ||
342 | RegisterConstant(field.Name, field.GetValue(target)); | ||
343 | } | ||
344 | } | ||
345 | } | ||
346 | |||
347 | /// <summary> | ||
348 | /// Operation to check for a registered constant | ||
349 | /// </summary> | ||
350 | public object LookupModConstant(string cname) | ||
351 | { | ||
352 | // m_log.DebugFormat("[MODULE COMMANDS] lookup constant <{0}>",cname); | ||
353 | |||
354 | lock (m_constants) | ||
355 | { | ||
356 | object value = null; | ||
357 | if (m_constants.TryGetValue(cname,out value)) | ||
358 | return value; | ||
359 | } | ||
360 | |||
361 | return null; | ||
362 | } | ||
363 | |||
364 | #endregion | ||
365 | |||
366 | } | ||
367 | } | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs index 008465f..1e1c7d0 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs | |||
@@ -56,6 +56,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset | |||
56 | 56 | ||
57 | private bool m_Enabled = false; | 57 | private bool m_Enabled = false; |
58 | 58 | ||
59 | private AssetPermissions m_AssetPerms; | ||
60 | |||
59 | public Type ReplaceableInterface | 61 | public Type ReplaceableInterface |
60 | { | 62 | { |
61 | get { return null; } | 63 | get { return null; } |
@@ -128,6 +130,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset | |||
128 | if (m_LocalAssetServiceURI != string.Empty) | 130 | if (m_LocalAssetServiceURI != string.Empty) |
129 | m_LocalAssetServiceURI = m_LocalAssetServiceURI.Trim('/'); | 131 | m_LocalAssetServiceURI = m_LocalAssetServiceURI.Trim('/'); |
130 | 132 | ||
133 | IConfig hgConfig = source.Configs["HGAssetService"]; | ||
134 | m_AssetPerms = new AssetPermissions(hgConfig); // it's ok if arg is null | ||
135 | |||
131 | m_Enabled = true; | 136 | m_Enabled = true; |
132 | m_log.Info("[HG ASSET CONNECTOR]: HG asset broker enabled"); | 137 | m_log.Info("[HG ASSET CONNECTOR]: HG asset broker enabled"); |
133 | } | 138 | } |
@@ -206,14 +211,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset | |||
206 | asset = m_HGService.Get(id); | 211 | asset = m_HGService.Get(id); |
207 | if (asset != null) | 212 | if (asset != null) |
208 | { | 213 | { |
209 | // Now store it locally | 214 | // Now store it locally, if allowed |
210 | // For now, let me just do it for textures and scripts | 215 | if (m_AssetPerms.AllowedImport(asset.Type)) |
211 | if (((AssetType)asset.Type == AssetType.Texture) || | ||
212 | ((AssetType)asset.Type == AssetType.LSLBytecode) || | ||
213 | ((AssetType)asset.Type == AssetType.LSLText)) | ||
214 | { | ||
215 | m_GridService.Store(asset); | 216 | m_GridService.Store(asset); |
216 | } | 217 | else |
218 | return null; | ||
217 | } | 219 | } |
218 | } | 220 | } |
219 | else | 221 | else |
@@ -328,7 +330,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset | |||
328 | 330 | ||
329 | string id = string.Empty; | 331 | string id = string.Empty; |
330 | if (IsHG(asset.ID)) | 332 | if (IsHG(asset.ID)) |
331 | id = m_HGService.Store(asset); | 333 | { |
334 | if (m_AssetPerms.AllowedExport(asset.Type)) | ||
335 | id = m_HGService.Store(asset); | ||
336 | else | ||
337 | return String.Empty; | ||
338 | } | ||
332 | else | 339 | else |
333 | id = m_GridService.Store(asset); | 340 | id = m_GridService.Store(asset); |
334 | 341 | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs index 57ae549..4338133 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs | |||
@@ -46,8 +46,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests | |||
46 | public class GridConnectorsTests : OpenSimTestCase | 46 | public class GridConnectorsTests : OpenSimTestCase |
47 | { | 47 | { |
48 | LocalGridServicesConnector m_LocalConnector; | 48 | LocalGridServicesConnector m_LocalConnector; |
49 | private void SetUp() | 49 | |
50 | [SetUp] | ||
51 | public override void SetUp() | ||
50 | { | 52 | { |
53 | base.SetUp(); | ||
54 | |||
51 | IConfigSource config = new IniConfigSource(); | 55 | IConfigSource config = new IniConfigSource(); |
52 | config.AddConfig("Modules"); | 56 | config.AddConfig("Modules"); |
53 | config.AddConfig("GridService"); | 57 | config.AddConfig("GridService"); |
@@ -71,8 +75,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests | |||
71 | TestHelpers.InMethod(); | 75 | TestHelpers.InMethod(); |
72 | // log4net.Config.XmlConfigurator.Configure(); | 76 | // log4net.Config.XmlConfigurator.Configure(); |
73 | 77 | ||
74 | SetUp(); | ||
75 | |||
76 | // Create 4 regions | 78 | // Create 4 regions |
77 | GridRegion r1 = new GridRegion(); | 79 | GridRegion r1 = new GridRegion(); |
78 | r1.RegionName = "Test Region 1"; | 80 | r1.RegionName = "Test Region 1"; |
diff --git a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs index 0a30905..82f49b0 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs | |||
@@ -65,8 +65,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
65 | protected TaskInventoryItem m_soundItem; | 65 | protected TaskInventoryItem m_soundItem; |
66 | 66 | ||
67 | [SetUp] | 67 | [SetUp] |
68 | public void SetUp() | 68 | public override void SetUp() |
69 | { | 69 | { |
70 | base.SetUp(); | ||
71 | |||
72 | // FIXME: Do something about this - relying on statics in unit tests causes trouble sooner or later | ||
70 | new SceneManager(); | 73 | new SceneManager(); |
71 | 74 | ||
72 | m_archiverModule = new ArchiverModule(); | 75 | m_archiverModule = new ArchiverModule(); |