diff options
author | Dr Scofield | 2009-02-09 09:16:15 +0000 |
---|---|---|
committer | Dr Scofield | 2009-02-09 09:16:15 +0000 |
commit | a89d097355526d4dc52a75a9734c6a02c3008ef4 (patch) | |
tree | f12e2cf5807762e0fbaf2f304e75b618f62b4cf6 /OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs | |
parent | adding bin/ScriptEngines/*/*.{dll,state}, bin/j2kDecodeCache, (diff) | |
download | opensim-SC-a89d097355526d4dc52a75a9734c6a02c3008ef4.zip opensim-SC-a89d097355526d4dc52a75a9734c6a02c3008ef4.tar.gz opensim-SC-a89d097355526d4dc52a75a9734c6a02c3008ef4.tar.bz2 opensim-SC-a89d097355526d4dc52a75a9734c6a02c3008ef4.tar.xz |
starting phase 2 of the OpenSim.Region.Environment commit: relocating
OpenSim.Region.Environment.Modules.Agent en bloc to OpenSim.Region.CoreModules
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs | 288 |
1 files changed, 0 insertions, 288 deletions
diff --git a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs deleted file mode 100644 index 1eb6795..0000000 --- a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs +++ /dev/null | |||
@@ -1,288 +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 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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenMetaverse; | ||
31 | using Nini.Config; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Region.Framework.Interfaces; | ||
34 | using OpenSim.Region.Framework.Scenes; | ||
35 | |||
36 | namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction | ||
37 | { | ||
38 | public class AssetTransactionModule : IRegionModule, IAgentAssetTransactions | ||
39 | { | ||
40 | private readonly Dictionary<UUID, Scene> RegisteredScenes = new Dictionary<UUID, Scene>(); | ||
41 | private bool m_dumpAssetsToFile = false; | ||
42 | private Scene m_scene = null; | ||
43 | |||
44 | public Scene MyScene | ||
45 | { | ||
46 | get{ return m_scene;} | ||
47 | } | ||
48 | |||
49 | /// <summary> | ||
50 | /// Each agent has its own singleton collection of transactions | ||
51 | /// </summary> | ||
52 | private Dictionary<UUID, AgentAssetTransactions> AgentTransactions = | ||
53 | new Dictionary<UUID, AgentAssetTransactions>(); | ||
54 | |||
55 | |||
56 | public AssetTransactionModule() | ||
57 | { | ||
58 | // System.Console.WriteLine("creating AgentAssetTransactionModule"); | ||
59 | } | ||
60 | |||
61 | #region IRegionModule Members | ||
62 | |||
63 | public void Initialise(Scene scene, IConfigSource config) | ||
64 | { | ||
65 | if (!RegisteredScenes.ContainsKey(scene.RegionInfo.RegionID)) | ||
66 | { | ||
67 | // System.Console.WriteLine("initialising AgentAssetTransactionModule"); | ||
68 | RegisteredScenes.Add(scene.RegionInfo.RegionID, scene); | ||
69 | scene.RegisterModuleInterface<IAgentAssetTransactions>(this); | ||
70 | |||
71 | scene.EventManager.OnNewClient += NewClient; | ||
72 | } | ||
73 | |||
74 | if (m_scene == null) | ||
75 | { | ||
76 | m_scene = scene; | ||
77 | if (config.Configs["StandAlone"] != null) | ||
78 | { | ||
79 | try | ||
80 | { | ||
81 | m_dumpAssetsToFile = config.Configs["StandAlone"].GetBoolean("dump_assets_to_file", false); | ||
82 | } | ||
83 | catch (Exception) | ||
84 | { | ||
85 | } | ||
86 | } | ||
87 | else | ||
88 | { | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | |||
93 | public void PostInitialise() | ||
94 | { | ||
95 | } | ||
96 | |||
97 | public void Close() | ||
98 | { | ||
99 | } | ||
100 | |||
101 | public string Name | ||
102 | { | ||
103 | get { return "AgentTransactionModule"; } | ||
104 | } | ||
105 | |||
106 | public bool IsSharedModule | ||
107 | { | ||
108 | get { return true; } | ||
109 | } | ||
110 | |||
111 | #endregion | ||
112 | |||
113 | public void NewClient(IClientAPI client) | ||
114 | { | ||
115 | client.OnAssetUploadRequest += HandleUDPUploadRequest; | ||
116 | client.OnXferReceive += HandleXfer; | ||
117 | } | ||
118 | |||
119 | #region AgentAssetTransactions | ||
120 | /// <summary> | ||
121 | /// Get the collection of asset transactions for the given user. If one does not already exist, it | ||
122 | /// is created. | ||
123 | /// </summary> | ||
124 | /// <param name="userID"></param> | ||
125 | /// <returns></returns> | ||
126 | private AgentAssetTransactions GetUserTransactions(UUID userID) | ||
127 | { | ||
128 | lock (AgentTransactions) | ||
129 | { | ||
130 | if (!AgentTransactions.ContainsKey(userID)) | ||
131 | { | ||
132 | AgentAssetTransactions transactions = new AgentAssetTransactions(userID, this, m_dumpAssetsToFile); | ||
133 | AgentTransactions.Add(userID, transactions); | ||
134 | } | ||
135 | |||
136 | return AgentTransactions[userID]; | ||
137 | } | ||
138 | } | ||
139 | |||
140 | /// <summary> | ||
141 | /// Remove the given agent asset transactions. This should be called when a client is departing | ||
142 | /// from a scene (and hence won't be making any more transactions here). | ||
143 | /// </summary> | ||
144 | /// <param name="userID"></param> | ||
145 | public void RemoveAgentAssetTransactions(UUID userID) | ||
146 | { | ||
147 | // m_log.DebugFormat("Removing agent asset transactions structure for agent {0}", userID); | ||
148 | |||
149 | lock (AgentTransactions) | ||
150 | { | ||
151 | AgentTransactions.Remove(userID); | ||
152 | } | ||
153 | } | ||
154 | |||
155 | /// <summary> | ||
156 | /// Create an inventory item from data that has been received through a transaction. | ||
157 | /// | ||
158 | /// This is called when new clothing or body parts are created. It may also be called in other | ||
159 | /// situations. | ||
160 | /// </summary> | ||
161 | /// <param name="remoteClient"></param> | ||
162 | /// <param name="transactionID"></param> | ||
163 | /// <param name="folderID"></param> | ||
164 | /// <param name="callbackID"></param> | ||
165 | /// <param name="description"></param> | ||
166 | /// <param name="name"></param> | ||
167 | /// <param name="invType"></param> | ||
168 | /// <param name="type"></param> | ||
169 | /// <param name="wearableType"></param> | ||
170 | /// <param name="nextOwnerMask"></param> | ||
171 | public void HandleItemCreationFromTransaction(IClientAPI remoteClient, UUID transactionID, UUID folderID, | ||
172 | uint callbackID, string description, string name, sbyte invType, | ||
173 | sbyte type, byte wearableType, uint nextOwnerMask) | ||
174 | { | ||
175 | // m_log.DebugFormat( | ||
176 | // "[TRANSACTIONS MANAGER] Called HandleItemCreationFromTransaction with item {0}", name); | ||
177 | |||
178 | AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); | ||
179 | |||
180 | transactions.RequestCreateInventoryItem( | ||
181 | remoteClient, transactionID, folderID, callbackID, description, | ||
182 | name, invType, type, wearableType, nextOwnerMask); | ||
183 | } | ||
184 | |||
185 | /// <summary> | ||
186 | /// Update an inventory item with data that has been received through a transaction. | ||
187 | /// | ||
188 | /// This is called when clothing or body parts are updated (for instance, with new textures or | ||
189 | /// colours). It may also be called in other situations. | ||
190 | /// </summary> | ||
191 | /// <param name="remoteClient"></param> | ||
192 | /// <param name="transactionID"></param> | ||
193 | /// <param name="item"></param> | ||
194 | public void HandleItemUpdateFromTransaction(IClientAPI remoteClient, UUID transactionID, | ||
195 | InventoryItemBase item) | ||
196 | { | ||
197 | // m_log.DebugFormat( | ||
198 | // "[TRANSACTIONS MANAGER] Called HandleItemUpdateFromTransaction with item {0}", | ||
199 | // item.Name); | ||
200 | |||
201 | AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); | ||
202 | |||
203 | transactions.RequestUpdateInventoryItem(remoteClient, transactionID, item); | ||
204 | } | ||
205 | |||
206 | /// <summary> | ||
207 | /// Update a task inventory item with data that has been received through a transaction. | ||
208 | /// | ||
209 | /// This is currently called when, for instance, a notecard in a prim is saved. The data is sent | ||
210 | /// up through a single AssetUploadRequest. A subsequent UpdateTaskInventory then references the transaction | ||
211 | /// and comes through this method. | ||
212 | /// </summary> | ||
213 | /// <param name="remoteClient"></param> | ||
214 | /// <param name="transactionID"></param> | ||
215 | /// <param name="item"></param> | ||
216 | public void HandleTaskItemUpdateFromTransaction( | ||
217 | IClientAPI remoteClient, SceneObjectPart part, UUID transactionID, TaskInventoryItem item) | ||
218 | { | ||
219 | // m_log.DebugFormat( | ||
220 | // "[TRANSACTIONS MANAGER] Called HandleTaskItemUpdateFromTransaction with item {0}", | ||
221 | // item.Name); | ||
222 | |||
223 | AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); | ||
224 | |||
225 | transactions.RequestUpdateTaskInventoryItem(remoteClient, part, 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="transaction"></param> | ||
234 | /// <param name="type"></param> | ||
235 | /// <param name="data"></param></param> | ||
236 | /// <param name="tempFile"></param> | ||
237 | public void HandleUDPUploadRequest(IClientAPI remoteClient, UUID assetID, UUID transaction, sbyte type, | ||
238 | byte[] data, bool storeLocal, bool tempFile) | ||
239 | { | ||
240 | //System.Console.WriteLine("HandleUDPUploadRequest - assetID: " + assetID.ToString() + " transaction: " + transaction.ToString() + " type: " + type.ToString() + " storelocal: " + storeLocal + " tempFile: " + tempFile); | ||
241 | if (((AssetType)type == AssetType.Texture || | ||
242 | (AssetType)type == AssetType.Sound || | ||
243 | (AssetType)type == AssetType.TextureTGA || | ||
244 | (AssetType)type == AssetType.Animation) && | ||
245 | tempFile == false) | ||
246 | { | ||
247 | Scene scene = (Scene)remoteClient.Scene; | ||
248 | IMoneyModule mm = scene.RequestModuleInterface<IMoneyModule>(); | ||
249 | |||
250 | if (mm != null) | ||
251 | { | ||
252 | if (!mm.UploadCovered(remoteClient)) | ||
253 | { | ||
254 | remoteClient.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false); | ||
255 | return; | ||
256 | } | ||
257 | } | ||
258 | } | ||
259 | |||
260 | //Console.WriteLine("asset upload of " + assetID); | ||
261 | AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); | ||
262 | |||
263 | AssetXferUploader uploader = transactions.RequestXferUploader(transaction); | ||
264 | if (uploader != null) | ||
265 | { | ||
266 | uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal, tempFile); | ||
267 | } | ||
268 | } | ||
269 | |||
270 | /// <summary> | ||
271 | /// Handle asset transfer data packets received in response to the asset upload request in | ||
272 | /// HandleUDPUploadRequest() | ||
273 | /// </summary> | ||
274 | /// <param name="remoteClient"></param> | ||
275 | /// <param name="xferID"></param> | ||
276 | /// <param name="packetID"></param> | ||
277 | /// <param name="data"></param> | ||
278 | public void HandleXfer(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data) | ||
279 | { | ||
280 | //System.Console.WriteLine("xferID: " + xferID + " packetID: " + packetID + " data!"); | ||
281 | AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); | ||
282 | |||
283 | transactions.HandleXfer(xferID, packetID, data); | ||
284 | } | ||
285 | |||
286 | #endregion | ||
287 | } | ||
288 | } | ||