aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetTransactionsManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetTransactionsManager.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetTransactionsManager.cs227
1 files changed, 227 insertions, 0 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}