diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs | 207 |
1 files changed, 207 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs new file mode 100644 index 0000000..09798aa --- /dev/null +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs | |||
@@ -0,0 +1,207 @@ | |||
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 | using System.Reflection; | ||
31 | |||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Region.Framework.Interfaces; | ||
34 | using OpenSim.Region.Framework.Scenes; | ||
35 | using OpenSim.Services.Connectors.Hypergrid; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | using OpenSim.Server.Base; | ||
38 | |||
39 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
40 | |||
41 | using OpenMetaverse; | ||
42 | using log4net; | ||
43 | using Nini.Config; | ||
44 | |||
45 | namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | ||
46 | { | ||
47 | public class HGInventoryAccessModule : InventoryAccessModule, INonSharedRegionModule, IInventoryAccessModule | ||
48 | { | ||
49 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
51 | private static HGAssetMapper m_assMapper; | ||
52 | public static HGAssetMapper AssetMapper | ||
53 | { | ||
54 | get { return m_assMapper; } | ||
55 | } | ||
56 | |||
57 | private bool m_Initialized = false; | ||
58 | |||
59 | #region INonSharedRegionModule | ||
60 | |||
61 | public override string Name | ||
62 | { | ||
63 | get { return "HGInventoryAccessModule"; } | ||
64 | } | ||
65 | |||
66 | public override void Initialise(IConfigSource source) | ||
67 | { | ||
68 | IConfig moduleConfig = source.Configs["Modules"]; | ||
69 | if (moduleConfig != null) | ||
70 | { | ||
71 | string name = moduleConfig.GetString("InventoryAccessModule", ""); | ||
72 | if (name == Name) | ||
73 | { | ||
74 | m_Enabled = true; | ||
75 | m_log.InfoFormat("[HG INVENTORY ACCESS MODULE]: {0} enabled.", Name); | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | |||
80 | public override void AddRegion(Scene scene) | ||
81 | { | ||
82 | if (!m_Enabled) | ||
83 | return; | ||
84 | |||
85 | base.AddRegion(scene); | ||
86 | m_assMapper = new HGAssetMapper(scene); | ||
87 | scene.EventManager.OnNewInventoryItemUploadComplete += UploadInventoryItem; | ||
88 | |||
89 | } | ||
90 | |||
91 | #endregion | ||
92 | |||
93 | #region Event handlers | ||
94 | |||
95 | public void UploadInventoryItem(UUID avatarID, UUID assetID, string name, int userlevel) | ||
96 | { | ||
97 | string userAssetServer = string.Empty; | ||
98 | if (IsForeignUser(avatarID, out userAssetServer)) | ||
99 | { | ||
100 | m_assMapper.Post(assetID, avatarID, userAssetServer); | ||
101 | } | ||
102 | } | ||
103 | |||
104 | #endregion | ||
105 | |||
106 | #region Overrides of Basic Inventory Access methods | ||
107 | /// | ||
108 | /// CapsUpdateInventoryItemAsset | ||
109 | /// | ||
110 | public override UUID CapsUpdateInventoryItemAsset(IClientAPI remoteClient, UUID itemID, byte[] data) | ||
111 | { | ||
112 | UUID newAssetID = base.CapsUpdateInventoryItemAsset(remoteClient, itemID, data); | ||
113 | |||
114 | UploadInventoryItem(remoteClient.AgentId, newAssetID, "", 0); | ||
115 | |||
116 | return newAssetID; | ||
117 | } | ||
118 | |||
119 | /// | ||
120 | /// DeleteToInventory | ||
121 | /// | ||
122 | public override UUID DeleteToInventory(DeRezAction action, UUID folderID, SceneObjectGroup objectGroup, IClientAPI remoteClient) | ||
123 | { | ||
124 | UUID assetID = base.DeleteToInventory(action, folderID, objectGroup, remoteClient); | ||
125 | |||
126 | if (!assetID.Equals(UUID.Zero)) | ||
127 | { | ||
128 | UploadInventoryItem(remoteClient.AgentId, assetID, "", 0); | ||
129 | } | ||
130 | else | ||
131 | m_log.Debug("[HGScene]: Scene.Inventory did not create asset"); | ||
132 | |||
133 | return assetID; | ||
134 | } | ||
135 | |||
136 | /// | ||
137 | /// RezObject | ||
138 | /// | ||
139 | public override SceneObjectGroup RezObject(IClientAPI remoteClient, UUID itemID, Vector3 RayEnd, Vector3 RayStart, | ||
140 | UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection, | ||
141 | bool RezSelected, bool RemoveItem, UUID fromTaskID, bool attachment) | ||
142 | { | ||
143 | m_log.DebugFormat("[HGScene] RezObject itemID={0} fromTaskID={1}", itemID, fromTaskID); | ||
144 | |||
145 | //if (fromTaskID.Equals(UUID.Zero)) | ||
146 | //{ | ||
147 | InventoryItemBase item = new InventoryItemBase(itemID); | ||
148 | item.Owner = remoteClient.AgentId; | ||
149 | item = m_Scene.InventoryService.GetItem(item); | ||
150 | //if (item == null) | ||
151 | //{ // Fetch the item | ||
152 | // item = new InventoryItemBase(); | ||
153 | // item.Owner = remoteClient.AgentId; | ||
154 | // item.ID = itemID; | ||
155 | // item = m_assMapper.Get(item, userInfo.RootFolder.ID, userInfo); | ||
156 | //} | ||
157 | string userAssetServer = string.Empty; | ||
158 | if (item != null && IsForeignUser(remoteClient.AgentId, out userAssetServer)) | ||
159 | { | ||
160 | m_assMapper.Get(item.AssetID, remoteClient.AgentId, userAssetServer); | ||
161 | |||
162 | } | ||
163 | //} | ||
164 | |||
165 | // OK, we're done fetching. Pass it up to the default RezObject | ||
166 | return base.RezObject(remoteClient, itemID, RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection, | ||
167 | RezSelected, RemoveItem, fromTaskID, attachment); | ||
168 | |||
169 | } | ||
170 | |||
171 | public override void TransferInventoryAssets(InventoryItemBase item, UUID sender, UUID receiver) | ||
172 | { | ||
173 | string userAssetServer = string.Empty; | ||
174 | if (IsForeignUser(sender, out userAssetServer)) | ||
175 | m_assMapper.Get(item.AssetID, sender, userAssetServer); | ||
176 | |||
177 | if (IsForeignUser(receiver, out userAssetServer)) | ||
178 | m_assMapper.Post(item.AssetID, receiver, userAssetServer); | ||
179 | } | ||
180 | |||
181 | #endregion | ||
182 | |||
183 | public bool IsForeignUser(UUID userID, out string assetServerURL) | ||
184 | { | ||
185 | assetServerURL = string.Empty; | ||
186 | UserAccount account = null; | ||
187 | if (m_Scene.UserAccountService != null) | ||
188 | account = m_Scene.UserAccountService.GetUserAccount(m_Scene.RegionInfo.ScopeID, userID); | ||
189 | |||
190 | if (account == null) // foreign | ||
191 | { | ||
192 | ScenePresence sp = null; | ||
193 | if (m_Scene.TryGetAvatar(userID, out sp)) | ||
194 | { | ||
195 | AgentCircuitData aCircuit = m_Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode); | ||
196 | if (aCircuit.ServiceURLs.ContainsKey("AssetServerURI")) | ||
197 | { | ||
198 | assetServerURL = aCircuit.ServiceURLs["AssetServerURI"].ToString(); | ||
199 | assetServerURL = assetServerURL.Trim(new char[] { '/' }); return true; | ||
200 | } | ||
201 | } | ||
202 | } | ||
203 | |||
204 | return false; | ||
205 | } | ||
206 | } | ||
207 | } | ||