aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetTransactionsManager.cs227
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs192
2 files changed, 227 insertions, 192 deletions
diff --git a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetTransactionsManager.cs b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetTransactionsManager.cs
new file mode 100644
index 0000000..69fdc01
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetTransactionsManager.cs
@@ -0,0 +1,227 @@
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 OpenSim 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
28using System.Collections.Generic;
29using System.Reflection;
30using log4net;
31using OpenMetaverse;
32using OpenSim.Framework;
33using OpenSim.Region.Environment.Scenes;
34using OpenSim.Region.Interfaces;
35
36namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction
37{
38 public class AgentAssetTransactionsManager
39 {
40 private static readonly ILog m_log
41 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42
43 /// <summary>
44 /// Each agent has its own singleton collection of transactions
45 /// </summary>
46 private Dictionary<UUID, AgentAssetTransactions> AgentTransactions =
47 new Dictionary<UUID, AgentAssetTransactions>();
48
49 /// <summary>
50 /// Should we dump uploaded assets to the filesystem?
51 /// </summary>
52 private bool m_dumpAssetsToFile;
53
54 public Scene MyScene;
55
56 public AgentAssetTransactionsManager(Scene scene, bool dumpAssetsToFile)
57 {
58 MyScene = scene;
59 m_dumpAssetsToFile = dumpAssetsToFile;
60 }
61
62 /// <summary>
63 /// Get the collection of asset transactions for the given user. If one does not already exist, it
64 /// is created.
65 /// </summary>
66 /// <param name="userID"></param>
67 /// <returns></returns>
68 private AgentAssetTransactions GetUserTransactions(UUID userID)
69 {
70 lock (AgentTransactions)
71 {
72 if (!AgentTransactions.ContainsKey(userID))
73 {
74 AgentAssetTransactions transactions
75 = new AgentAssetTransactions(userID, this, m_dumpAssetsToFile);
76 AgentTransactions.Add(userID, transactions);
77 }
78
79 return AgentTransactions[userID];
80 }
81 }
82
83 /// <summary>
84 /// Remove the given agent asset transactions. This should be called when a client is departing
85 /// from a scene (and hence won't be making any more transactions here).
86 /// </summary>
87 /// <param name="userID"></param>
88 public void RemoveAgentAssetTransactions(UUID userID)
89 {
90 // m_log.DebugFormat("Removing agent asset transactions structure for agent {0}", userID);
91
92 lock (AgentTransactions)
93 {
94 AgentTransactions.Remove(userID);
95 }
96 }
97
98 /// <summary>
99 /// Create an inventory item from data that has been received through a transaction.
100 ///
101 /// This is called when new clothing or body parts are created. It may also be called in other
102 /// situations.
103 /// </summary>
104 /// <param name="remoteClient"></param>
105 /// <param name="transactionID"></param>
106 /// <param name="folderID"></param>
107 /// <param name="callbackID"></param>
108 /// <param name="description"></param>
109 /// <param name="name"></param>
110 /// <param name="invType"></param>
111 /// <param name="type"></param>
112 /// <param name="wearableType"></param>
113 /// <param name="nextOwnerMask"></param>
114 public void HandleItemCreationFromTransaction(IClientAPI remoteClient, UUID transactionID, UUID folderID,
115 uint callbackID, string description, string name, sbyte invType,
116 sbyte type, byte wearableType, uint nextOwnerMask)
117 {
118// m_log.DebugFormat(
119// "[TRANSACTIONS MANAGER] Called HandleItemCreationFromTransaction with item {0}", name);
120
121 AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
122
123 transactions.RequestCreateInventoryItem(
124 remoteClient, transactionID, folderID, callbackID, description,
125 name, invType, type, wearableType, nextOwnerMask);
126 }
127
128 /// <summary>
129 /// Update an inventory item with data that has been received through a transaction.
130 ///
131 /// This is called when clothing or body parts are updated (for instance, with new textures or
132 /// colours). It may also be called in other situations.
133 /// </summary>
134 /// <param name="remoteClient"></param>
135 /// <param name="transactionID"></param>
136 /// <param name="item"></param>
137 public void HandleItemUpdateFromTransaction(IClientAPI remoteClient, UUID transactionID,
138 InventoryItemBase item)
139 {
140// m_log.DebugFormat(
141// "[TRANSACTIONS MANAGER] Called HandleItemUpdateFromTransaction with item {0}",
142// item.Name);
143
144 AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
145
146 transactions.RequestUpdateInventoryItem(remoteClient, transactionID, item);
147 }
148
149 /// <summary>
150 /// Update a task inventory item with data that has been received through a transaction.
151 ///
152 /// This is currently called when, for instance, a notecard in a prim is saved. The data is sent
153 /// up through a single AssetUploadRequest. A subsequent UpdateTaskInventory then references the transaction
154 /// and comes through this method.
155 /// </summary>
156 /// <param name="remoteClient"></param>
157 /// <param name="transactionID"></param>
158 /// <param name="item"></param>
159 public void HandleTaskItemUpdateFromTransaction(
160 IClientAPI remoteClient, SceneObjectPart part, UUID transactionID, TaskInventoryItem item)
161 {
162// m_log.DebugFormat(
163// "[TRANSACTIONS MANAGER] Called HandleTaskItemUpdateFromTransaction with item {0}",
164// item.Name);
165
166 AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
167
168 transactions.RequestUpdateTaskInventoryItem(remoteClient, part, transactionID, item);
169 }
170
171 /// <summary>
172 /// Request that a client (agent) begin an asset transfer.
173 /// </summary>
174 /// <param name="remoteClient"></param>
175 /// <param name="assetID"></param>
176 /// <param name="transaction"></param>
177 /// <param name="type"></param>
178 /// <param name="data"></param></param>
179 /// <param name="tempFile"></param>
180 public void HandleUDPUploadRequest(IClientAPI remoteClient, UUID assetID, UUID transaction, sbyte type,
181 byte[] data, bool storeLocal, bool tempFile)
182 {
183 if (((AssetType)type == AssetType.Texture ||
184 (AssetType)type == AssetType.Sound ||
185 (AssetType)type == AssetType.TextureTGA ||
186 (AssetType)type == AssetType.Animation) &&
187 tempFile == false)
188 {
189 Scene scene = (Scene)remoteClient.Scene;
190 IMoneyModule mm = scene.RequestModuleInterface<IMoneyModule>();
191
192 if (mm != null)
193 {
194 if (!mm.UploadCovered(remoteClient))
195 {
196 remoteClient.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false);
197 return;
198 }
199 }
200 }
201
202 //Console.WriteLine("asset upload of " + assetID);
203 AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
204
205 AgentAssetTransactions.AssetXferUploader uploader = transactions.RequestXferUploader(transaction);
206 if (uploader != null)
207 {
208 uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal, tempFile);
209 }
210 }
211
212 /// <summary>
213 /// Handle asset transfer data packets received in response to the asset upload request in
214 /// HandleUDPUploadRequest()
215 /// </summary>
216 /// <param name="remoteClient"></param>
217 /// <param name="xferID"></param>
218 /// <param name="packetID"></param>
219 /// <param name="data"></param>
220 public void HandleXfer(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data)
221 {
222 AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
223
224 transactions.HandleXfer(xferID, packetID, data);
225 }
226 }
227}
diff --git a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs
index 56ca1a1..09c9aef 100644
--- a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs
+++ b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs
@@ -27,9 +27,7 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Reflection;
31using OpenMetaverse; 30using OpenMetaverse;
32using log4net;
33using Nini.Config; 31using Nini.Config;
34using OpenSim.Framework; 32using OpenSim.Framework;
35using OpenSim.Region.Interfaces; 33using OpenSim.Region.Interfaces;
@@ -140,194 +138,4 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction
140 client.OnXferReceive += m_transactionManager.HandleXfer; 138 client.OnXferReceive += m_transactionManager.HandleXfer;
141 } 139 }
142 } 140 }
143
144 public class AgentAssetTransactionsManager
145 {
146 private static readonly ILog m_log
147 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
148
149 /// <summary>
150 /// Each agent has its own singleton collection of transactions
151 /// </summary>
152 private Dictionary<UUID, AgentAssetTransactions> AgentTransactions =
153 new Dictionary<UUID, AgentAssetTransactions>();
154
155 /// <summary>
156 /// Should we dump uploaded assets to the filesystem?
157 /// </summary>
158 private bool m_dumpAssetsToFile;
159
160 public Scene MyScene;
161
162 public AgentAssetTransactionsManager(Scene scene, bool dumpAssetsToFile)
163 {
164 MyScene = scene;
165 m_dumpAssetsToFile = dumpAssetsToFile;
166 }
167
168 /// <summary>
169 /// Get the collection of asset transactions for the given user. If one does not already exist, it
170 /// is created.
171 /// </summary>
172 /// <param name="userID"></param>
173 /// <returns></returns>
174 private AgentAssetTransactions GetUserTransactions(UUID userID)
175 {
176 lock (AgentTransactions)
177 {
178 if (!AgentTransactions.ContainsKey(userID))
179 {
180 AgentAssetTransactions transactions
181 = new AgentAssetTransactions(userID, this, m_dumpAssetsToFile);
182 AgentTransactions.Add(userID, transactions);
183 }
184
185 return AgentTransactions[userID];
186 }
187 }
188
189 /// <summary>
190 /// Remove the given agent asset transactions. This should be called when a client is departing
191 /// from a scene (and hence won't be making any more transactions here).
192 /// </summary>
193 /// <param name="userID"></param>
194 public void RemoveAgentAssetTransactions(UUID userID)
195 {
196 // m_log.DebugFormat("Removing agent asset transactions structure for agent {0}", userID);
197
198 lock (AgentTransactions)
199 {
200 AgentTransactions.Remove(userID);
201 }
202 }
203
204 /// <summary>
205 /// Create an inventory item from data that has been received through a transaction.
206 ///
207 /// This is called when new clothing or body parts are created. It may also be called in other
208 /// situations.
209 /// </summary>
210 /// <param name="remoteClient"></param>
211 /// <param name="transactionID"></param>
212 /// <param name="folderID"></param>
213 /// <param name="callbackID"></param>
214 /// <param name="description"></param>
215 /// <param name="name"></param>
216 /// <param name="invType"></param>
217 /// <param name="type"></param>
218 /// <param name="wearableType"></param>
219 /// <param name="nextOwnerMask"></param>
220 public void HandleItemCreationFromTransaction(IClientAPI remoteClient, UUID transactionID, UUID folderID,
221 uint callbackID, string description, string name, sbyte invType,
222 sbyte type, byte wearableType, uint nextOwnerMask)
223 {
224// m_log.DebugFormat(
225// "[TRANSACTIONS MANAGER] Called HandleItemCreationFromTransaction with item {0}", name);
226
227 AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
228
229 transactions.RequestCreateInventoryItem(
230 remoteClient, transactionID, folderID, callbackID, description,
231 name, invType, type, wearableType, nextOwnerMask);
232 }
233
234 /// <summary>
235 /// Update an inventory item with data that has been received through a transaction.
236 ///
237 /// This is called when clothing or body parts are updated (for instance, with new textures or
238 /// colours). It may also be called in other situations.
239 /// </summary>
240 /// <param name="remoteClient"></param>
241 /// <param name="transactionID"></param>
242 /// <param name="item"></param>
243 public void HandleItemUpdateFromTransaction(IClientAPI remoteClient, UUID transactionID,
244 InventoryItemBase item)
245 {
246// m_log.DebugFormat(
247// "[TRANSACTIONS MANAGER] Called HandleItemUpdateFromTransaction with item {0}",
248// item.Name);
249
250 AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
251
252 transactions.RequestUpdateInventoryItem(remoteClient, transactionID, item);
253 }
254
255 /// <summary>
256 /// Update a task inventory item with data that has been received through a transaction.
257 ///
258 /// This is currently called when, for instance, a notecard in a prim is saved. The data is sent
259 /// up through a single AssetUploadRequest. A subsequent UpdateTaskInventory then references the transaction
260 /// and comes through this method.
261 /// </summary>
262 /// <param name="remoteClient"></param>
263 /// <param name="transactionID"></param>
264 /// <param name="item"></param>
265 public void HandleTaskItemUpdateFromTransaction(
266 IClientAPI remoteClient, SceneObjectPart part, UUID transactionID, TaskInventoryItem item)
267 {
268// m_log.DebugFormat(
269// "[TRANSACTIONS MANAGER] Called HandleTaskItemUpdateFromTransaction with item {0}",
270// item.Name);
271
272 AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
273
274 transactions.RequestUpdateTaskInventoryItem(remoteClient, part, transactionID, item);
275 }
276
277 /// <summary>
278 /// Request that a client (agent) begin an asset transfer.
279 /// </summary>
280 /// <param name="remoteClient"></param>
281 /// <param name="assetID"></param>
282 /// <param name="transaction"></param>
283 /// <param name="type"></param>
284 /// <param name="data"></param></param>
285 /// <param name="tempFile"></param>
286 public void HandleUDPUploadRequest(IClientAPI remoteClient, UUID assetID, UUID transaction, sbyte type,
287 byte[] data, bool storeLocal, bool tempFile)
288 {
289 if (((AssetType)type == AssetType.Texture ||
290 (AssetType)type == AssetType.Sound ||
291 (AssetType)type == AssetType.TextureTGA ||
292 (AssetType)type == AssetType.Animation) &&
293 tempFile == false)
294 {
295 Scene scene = (Scene)remoteClient.Scene;
296 IMoneyModule mm = scene.RequestModuleInterface<IMoneyModule>();
297
298 if (mm != null)
299 {
300 if (!mm.UploadCovered(remoteClient))
301 {
302 remoteClient.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false);
303 return;
304 }
305 }
306 }
307
308 //Console.WriteLine("asset upload of " + assetID);
309 AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
310
311 AgentAssetTransactions.AssetXferUploader uploader = transactions.RequestXferUploader(transaction);
312 if (uploader != null)
313 {
314 uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal, tempFile);
315 }
316 }
317
318 /// <summary>
319 /// Handle asset transfer data packets received in response to the asset upload request in
320 /// HandleUDPUploadRequest()
321 /// </summary>
322 /// <param name="remoteClient"></param>
323 /// <param name="xferID"></param>
324 /// <param name="packetID"></param>
325 /// <param name="data"></param>
326 public void HandleXfer(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data)
327 {
328 AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
329
330 transactions.HandleXfer(xferID, packetID, data);
331 }
332 }
333} 141}