opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 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 | using log4net; |
||
32 | using Nini.Config; |
||
33 | using OpenMetaverse; |
||
34 | using OpenSim.Framework; |
||
35 | using OpenSim.Region.Framework.Interfaces; |
||
36 | using OpenSim.Region.Framework.Scenes; |
||
37 | using Mono.Addins; |
||
38 | |||
39 | namespace OpenSim.Region.CoreModules.Agent.AssetTransaction |
||
40 | { |
||
41 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AssetTransactionModule")] |
||
42 | public class AssetTransactionModule : INonSharedRegionModule, |
||
43 | IAgentAssetTransactions |
||
44 | { |
||
45 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
46 | |||
47 | protected Scene m_Scene; |
||
48 | private bool m_dumpAssetsToFile = false; |
||
49 | private int m_levelUpload = 0; |
||
50 | |||
51 | /// <summary> |
||
52 | /// Each agent has its own singleton collection of transactions |
||
53 | /// </summary> |
||
54 | private Dictionary<UUID, AgentAssetTransactions> AgentTransactions = |
||
55 | new Dictionary<UUID, AgentAssetTransactions>(); |
||
56 | |||
57 | #region Region Module interface |
||
58 | |||
59 | public void Initialise(IConfigSource source) |
||
60 | { |
||
61 | IConfig sconfig = source.Configs["Startup"]; |
||
62 | if (sconfig != null) |
||
63 | { |
||
64 | m_levelUpload = sconfig.GetInt("LevelUpload", 0); |
||
65 | } |
||
66 | } |
||
67 | |||
68 | public void AddRegion(Scene scene) |
||
69 | { |
||
70 | m_Scene = scene; |
||
71 | scene.RegisterModuleInterface<IAgentAssetTransactions>(this); |
||
72 | scene.EventManager.OnNewClient += NewClient; |
||
73 | } |
||
74 | |||
75 | public void RegionLoaded(Scene scene) |
||
76 | { |
||
77 | } |
||
78 | |||
79 | public void RemoveRegion(Scene scene) |
||
80 | { |
||
81 | } |
||
82 | |||
83 | public void Close() |
||
84 | { |
||
85 | } |
||
86 | |||
87 | public string Name |
||
88 | { |
||
89 | get { return "AgentTransactionModule"; } |
||
90 | } |
||
91 | |||
92 | public Type ReplaceableInterface |
||
93 | { |
||
94 | get { return typeof(IAgentAssetTransactions); } |
||
95 | } |
||
96 | |||
97 | #endregion |
||
98 | |||
99 | public void NewClient(IClientAPI client) |
||
100 | { |
||
101 | client.OnAssetUploadRequest += HandleUDPUploadRequest; |
||
102 | client.OnXferReceive += HandleXfer; |
||
103 | } |
||
104 | |||
105 | #region AgentAssetTransactions |
||
106 | /// <summary> |
||
107 | /// Get the collection of asset transactions for the given user. |
||
108 | /// If one does not already exist, it is created. |
||
109 | /// </summary> |
||
110 | /// <param name="userID"></param> |
||
111 | /// <returns></returns> |
||
112 | private AgentAssetTransactions GetUserTransactions(UUID userID) |
||
113 | { |
||
114 | lock (AgentTransactions) |
||
115 | { |
||
116 | if (!AgentTransactions.ContainsKey(userID)) |
||
117 | { |
||
118 | AgentAssetTransactions transactions = |
||
119 | new AgentAssetTransactions(userID, m_Scene, |
||
120 | m_dumpAssetsToFile); |
||
121 | |||
122 | AgentTransactions.Add(userID, transactions); |
||
123 | } |
||
124 | |||
125 | return AgentTransactions[userID]; |
||
126 | } |
||
127 | } |
||
128 | |||
129 | /// <summary> |
||
130 | /// Remove the given agent asset transactions. This should be called |
||
131 | /// when a client is departing from a scene (and hence won't be making |
||
132 | /// any more transactions here). |
||
133 | /// </summary> |
||
134 | /// <param name="userID"></param> |
||
135 | public void RemoveAgentAssetTransactions(UUID userID) |
||
136 | { |
||
137 | // m_log.DebugFormat("Removing agent asset transactions structure for agent {0}", userID); |
||
138 | |||
139 | lock (AgentTransactions) |
||
140 | { |
||
141 | AgentTransactions.Remove(userID); |
||
142 | } |
||
143 | } |
||
144 | |||
145 | /// <summary> |
||
146 | /// Create an inventory item from data that has been received through |
||
147 | /// a transaction. |
||
148 | /// This is called when new clothing or body parts are created. |
||
149 | /// It may also be called in other situations. |
||
150 | /// </summary> |
||
151 | /// <param name="remoteClient"></param> |
||
152 | /// <param name="transactionID"></param> |
||
153 | /// <param name="folderID"></param> |
||
154 | /// <param name="callbackID"></param> |
||
155 | /// <param name="description"></param> |
||
156 | /// <param name="name"></param> |
||
157 | /// <param name="invType"></param> |
||
158 | /// <param name="type"></param> |
||
159 | /// <param name="wearableType"></param> |
||
160 | /// <param name="nextOwnerMask"></param> |
||
161 | public void HandleItemCreationFromTransaction(IClientAPI remoteClient, |
||
162 | UUID transactionID, UUID folderID, uint callbackID, |
||
163 | string description, string name, sbyte invType, |
||
164 | sbyte type, byte wearableType, uint nextOwnerMask) |
||
165 | { |
||
166 | // m_log.DebugFormat( |
||
167 | // "[TRANSACTIONS MANAGER] Called HandleItemCreationFromTransaction with item {0}", name); |
||
168 | |||
169 | AgentAssetTransactions transactions = |
||
170 | GetUserTransactions(remoteClient.AgentId); |
||
171 | |||
172 | transactions.RequestCreateInventoryItem(remoteClient, transactionID, |
||
173 | folderID, callbackID, description, name, invType, type, |
||
174 | wearableType, nextOwnerMask); |
||
175 | } |
||
176 | |||
177 | /// <summary> |
||
178 | /// Update an inventory item with data that has been received through a |
||
179 | /// transaction. |
||
180 | /// </summary> |
||
181 | /// <remarks> |
||
182 | /// This is called when clothing or body parts are updated (for |
||
183 | /// instance, with new textures or colours). It may also be called in |
||
184 | /// other situations. |
||
185 | /// </remarks> |
||
186 | /// <param name="remoteClient"></param> |
||
187 | /// <param name="transactionID"></param> |
||
188 | /// <param name="item"></param> |
||
189 | public void HandleItemUpdateFromTransaction(IClientAPI remoteClient, |
||
190 | UUID transactionID, InventoryItemBase item) |
||
191 | { |
||
192 | // m_log.DebugFormat( |
||
193 | // "[ASSET TRANSACTION MODULE]: Called HandleItemUpdateFromTransaction with item {0}", |
||
194 | // item.Name); |
||
195 | |||
196 | AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); |
||
197 | |||
198 | transactions.RequestUpdateInventoryItem(remoteClient, transactionID, item); |
||
199 | } |
||
200 | |||
201 | /// <summary> |
||
202 | /// Update a task inventory item with data that has been received |
||
203 | /// through a transaction. |
||
204 | /// |
||
205 | /// This is currently called when, for instance, a notecard in a prim |
||
206 | /// is saved. The data is sent up through a single AssetUploadRequest. |
||
207 | /// A subsequent UpdateTaskInventory then references the transaction |
||
208 | /// and comes through this method. |
||
209 | /// </summary> |
||
210 | /// <param name="remoteClient"></param> |
||
211 | /// <param name="part"></param> |
||
212 | /// <param name="transactionID"></param> |
||
213 | /// <param name="item"></param> |
||
214 | public void HandleTaskItemUpdateFromTransaction( |
||
215 | IClientAPI remoteClient, SceneObjectPart part, UUID transactionID, TaskInventoryItem item) |
||
216 | { |
||
217 | // m_log.DebugFormat( |
||
218 | // "[ASSET TRANSACTION MODULE]: Called HandleTaskItemUpdateFromTransaction with item {0} in {1} for {2} in {3}", |
||
219 | // item.Name, part.Name, remoteClient.Name, m_Scene.RegionInfo.RegionName); |
||
220 | |||
221 | AgentAssetTransactions transactions = |
||
222 | GetUserTransactions(remoteClient.AgentId); |
||
223 | |||
224 | transactions.RequestUpdateTaskInventoryItem(remoteClient, part, |
||
225 | transactionID, item); |
||
226 | } |
||
227 | |||
228 | /// <summary> |
||
229 | /// Request that a client (agent) begin an asset transfer. |
||
230 | /// </summary> |
||
231 | /// <param name="remoteClient"></param> |
||
232 | /// <param name="assetID"></param> |
||
233 | /// <param name="transactionID"></param> |
||
234 | /// <param name="type"></param> |
||
235 | /// <param name="data"></param></param> |
||
236 | /// <param name="tempFile"></param> |
||
237 | public void HandleUDPUploadRequest(IClientAPI remoteClient, |
||
238 | UUID assetID, UUID transactionID, sbyte type, byte[] data, |
||
239 | bool storeLocal, bool tempFile) |
||
240 | { |
||
241 | // m_log.DebugFormat( |
||
242 | // "[ASSET TRANSACTION MODULE]: HandleUDPUploadRequest - assetID: {0}, transaction {1}, type {2}, storeLocal {3}, tempFile {4}, data.Length {5}", |
||
243 | // assetID, transactionID, type, storeLocal, tempFile, data.Length); |
||
244 | |||
245 | if (((AssetType)type == AssetType.Texture || |
||
246 | (AssetType)type == AssetType.Sound || |
||
247 | (AssetType)type == AssetType.TextureTGA || |
||
248 | (AssetType)type == AssetType.Animation) && |
||
249 | tempFile == false) |
||
250 | { |
||
251 | ScenePresence avatar = null; |
||
252 | Scene scene = (Scene)remoteClient.Scene; |
||
253 | scene.TryGetScenePresence(remoteClient.AgentId, out avatar); |
||
254 | |||
255 | // check user level |
||
256 | if (avatar != null) |
||
257 | { |
||
258 | if (avatar.UserLevel < m_levelUpload) |
||
259 | { |
||
260 | remoteClient.SendAgentAlertMessage("Unable to upload asset. Insufficient permissions.", false); |
||
261 | return; |
||
262 | } |
||
263 | } |
||
264 | |||
265 | // check funds |
||
266 | IMoneyModule mm = scene.RequestModuleInterface<IMoneyModule>(); |
||
267 | |||
268 | if (mm != null) |
||
269 | { |
||
270 | if (!mm.UploadCovered(remoteClient.AgentId, mm.UploadCharge)) |
||
271 | { |
||
272 | remoteClient.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false); |
||
273 | return; |
||
274 | } |
||
275 | } |
||
276 | } |
||
277 | |||
278 | AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); |
||
279 | AssetXferUploader uploader = transactions.RequestXferUploader(transactionID); |
||
280 | uploader.StartUpload(remoteClient, assetID, transactionID, type, data, storeLocal, tempFile); |
||
281 | } |
||
282 | |||
283 | /// <summary> |
||
284 | /// Handle asset transfer data packets received in response to the |
||
285 | /// asset upload request in HandleUDPUploadRequest() |
||
286 | /// </summary> |
||
287 | /// <param name="remoteClient"></param> |
||
288 | /// <param name="xferID"></param> |
||
289 | /// <param name="packetID"></param> |
||
290 | /// <param name="data"></param> |
||
291 | public void HandleXfer(IClientAPI remoteClient, ulong xferID, |
||
292 | uint packetID, byte[] data) |
||
293 | { |
||
294 | // m_log.Debug("xferID: " + xferID + " packetID: " + packetID + " data length " + data.Length); |
||
295 | AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); |
||
296 | |||
297 | transactions.HandleXfer(xferID, packetID, data); |
||
298 | } |
||
299 | |||
300 | #endregion |
||
301 | } |
||
302 | } |