aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs
diff options
context:
space:
mode:
authorAdam Frisby2008-04-30 21:16:36 +0000
committerAdam Frisby2008-04-30 21:16:36 +0000
commitf5c312bc3c2567449c7268a54a08a54119f58d53 (patch)
tree424668a4bbec6873ebc5b8256f3671db102f5e9c /OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs
parent* Adds the AuthbuyerID field to sqlite and makes use of it. (diff)
downloadopensim-SC_OLD-f5c312bc3c2567449c7268a54a08a54119f58d53.zip
opensim-SC_OLD-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.gz
opensim-SC_OLD-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.bz2
opensim-SC_OLD-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.xz
* Refactored Environment/Modules directory - modules now reside in their own directory with any associated module-specific classes.
* Each module directory is currently inside one of the following category folders: Agent (Anything relating to do with Client<->Server communications.), Avatar (Anything to do with the avatar or presence inworld), Framework (Classes modules can use), Grid (Grid traffic, new OGS2 grid comms), Scripting (Scripting functions, etc), World (The enrivonment/scene, IE Sun/Tree modules.) * This should be moved into a seperate project file.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs286
1 files changed, 286 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs
new file mode 100644
index 0000000..ef81625
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs
@@ -0,0 +1,286 @@
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;
29using System.Collections.Generic;
30using System.Reflection;
31using libsecondlife;
32using log4net;
33using Nini.Config;
34using OpenSim.Framework;
35using OpenSim.Region.Environment.Interfaces;
36using OpenSim.Region.Environment.Modules.Agent.AssetTransaction;
37using OpenSim.Region.Environment.Scenes;
38
39namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction
40{
41 public class AssetTransactionModule : IRegionModule, IAgentAssetTransactions
42 {
43 private readonly Dictionary<LLUUID, Scene> RegisteredScenes = new Dictionary<LLUUID, Scene>();
44 private Scene m_scene = null;
45 private bool m_dumpAssetsToFile = false;
46
47 private AgentAssetTransactionsManager m_transactionManager;
48
49 public AssetTransactionModule()
50 {
51 // System.Console.WriteLine("creating AgentAssetTransactionModule");
52 }
53
54 public void Initialise(Scene scene, IConfigSource config)
55 {
56 if (!RegisteredScenes.ContainsKey(scene.RegionInfo.RegionID))
57 {
58 // System.Console.WriteLine("initialising AgentAssetTransactionModule");
59 RegisteredScenes.Add(scene.RegionInfo.RegionID, scene);
60 scene.RegisterModuleInterface<IAgentAssetTransactions>(this);
61
62 scene.EventManager.OnNewClient += NewClient;
63 }
64
65 if (m_scene == null)
66 {
67 m_scene = scene;
68 if (config.Configs["StandAlone"] != null)
69 {
70 try
71 {
72 m_dumpAssetsToFile = config.Configs["StandAlone"].GetBoolean("dump_assets_to_file", false);
73 m_transactionManager = new AgentAssetTransactionsManager(m_scene, m_dumpAssetsToFile);
74 }
75 catch (Exception)
76 {
77 m_transactionManager = new AgentAssetTransactionsManager(m_scene, false);
78 }
79 }
80 else
81 {
82 m_transactionManager = new AgentAssetTransactionsManager(m_scene, false);
83 }
84
85 }
86 }
87
88 public void PostInitialise()
89 {
90
91 }
92
93 public void Close()
94 {
95 }
96
97 public string Name
98 {
99 get { return "AgentTransactionModule"; }
100 }
101
102 public bool IsSharedModule
103 {
104 get { return true; }
105 }
106
107 public void NewClient(IClientAPI client)
108 {
109 client.OnAssetUploadRequest += m_transactionManager.HandleUDPUploadRequest;
110 client.OnXferReceive += m_transactionManager.HandleXfer;
111 }
112
113 public void HandleItemCreationFromTransaction(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID,
114 uint callbackID, string description, string name, sbyte invType,
115 sbyte type, byte wearableType, uint nextOwnerMask)
116 {
117 m_transactionManager.HandleItemCreationFromTransaction(remoteClient, transactionID, folderID, callbackID, description, name, invType, type, wearableType, nextOwnerMask);
118 }
119
120 public void HandleItemUpdateFromTransaction(IClientAPI remoteClient, LLUUID transactionID,
121 InventoryItemBase item)
122 {
123 m_transactionManager.HandleItemUpdateFromTransaction(remoteClient, transactionID, item);
124 }
125
126 public void RemoveAgentAssetTransactions(LLUUID userID)
127 {
128 m_transactionManager.RemoveAgentAssetTransactions(userID);
129 }
130 }
131
132 public class AgentAssetTransactionsManager
133 {
134 private static readonly ILog m_log
135 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
136
137 // Fields
138 public Scene MyScene;
139
140 /// <summary>
141 /// Each agent has its own singleton collection of transactions
142 /// </summary>
143 private Dictionary<LLUUID, AgentAssetTransactions> AgentTransactions =
144 new Dictionary<LLUUID, AgentAssetTransactions>();
145
146 /// <summary>
147 /// Should we dump uploaded assets to the filesystem?
148 /// </summary>
149 private bool m_dumpAssetsToFile;
150
151 public AgentAssetTransactionsManager(Scene scene, bool dumpAssetsToFile)
152 {
153 MyScene = scene;
154 m_dumpAssetsToFile = dumpAssetsToFile;
155 }
156
157 /// <summary>
158 /// Get the collection of asset transactions for the given user. If one does not already exist, it
159 /// is created.
160 /// </summary>
161 /// <param name="userID"></param>
162 /// <returns></returns>
163 private AgentAssetTransactions GetUserTransactions(LLUUID userID)
164 {
165 lock (AgentTransactions)
166 {
167 if (!AgentTransactions.ContainsKey(userID))
168 {
169 AgentAssetTransactions transactions
170 = new AgentAssetTransactions(userID, this, m_dumpAssetsToFile);
171 AgentTransactions.Add(userID, transactions);
172 }
173
174 return AgentTransactions[userID];
175 }
176 }
177
178 /// <summary>
179 /// Remove the given agent asset transactions. This should be called when a client is departing
180 /// from a scene (and hence won't be making any more transactions here).
181 /// </summary>
182 /// <param name="userID"></param>
183 public void RemoveAgentAssetTransactions(LLUUID userID)
184 {
185 // m_log.DebugFormat("Removing agent asset transactions structure for agent {0}", userID);
186
187 lock (AgentTransactions)
188 {
189 AgentTransactions.Remove(userID);
190 }
191 }
192
193 /// <summary>
194 /// Create an inventory item from data that has been received through a transaction.
195 ///
196 /// This is called when new clothing or body parts are created. It may also be called in other
197 /// situations.
198 /// </summary>
199 /// <param name="remoteClient"></param>
200 /// <param name="transactionID"></param>
201 /// <param name="folderID"></param>
202 /// <param name="callbackID"></param>
203 /// <param name="description"></param>
204 /// <param name="name"></param>
205 /// <param name="invType"></param>
206 /// <param name="type"></param>
207 /// <param name="wearableType"></param>
208 /// <param name="nextOwnerMask"></param>
209 public void HandleItemCreationFromTransaction(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID,
210 uint callbackID, string description, string name, sbyte invType,
211 sbyte type, byte wearableType, uint nextOwnerMask)
212 {
213 m_log.DebugFormat(
214 "[TRANSACTIONS MANAGER] Called HandleItemCreationFromTransaction with item {0}", name);
215
216 AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
217
218 transactions.RequestCreateInventoryItem(
219 remoteClient, transactionID, folderID, callbackID, description,
220 name, invType, type, wearableType, nextOwnerMask);
221 }
222
223 /// <summary>
224 /// Update an inventory item with data that has been received through a transaction.
225 ///
226 /// This is called when clothing or body parts are updated (for instance, with new textures or
227 /// colours). It may also be called in other situations.
228 /// </summary>
229 /// <param name="remoteClient"></param>
230 /// <param name="transactionID"></param>
231 /// <param name="item"></param>
232 public void HandleItemUpdateFromTransaction(IClientAPI remoteClient, LLUUID transactionID,
233 InventoryItemBase item)
234 {
235 m_log.DebugFormat(
236 "[TRANSACTIONS MANAGER] Called HandleItemUpdateFromTransaction with item {0}",
237 item.Name);
238
239 AgentAssetTransactions transactions
240 = GetUserTransactions(remoteClient.AgentId);
241
242 transactions.RequestUpdateInventoryItem(remoteClient, transactionID, item);
243 }
244
245 /// <summary>
246 /// Request that a client (agent) begin an asset transfer.
247 /// </summary>
248 /// <param name="remoteClient"></param>
249 /// <param name="assetID"></param>
250 /// <param name="transaction"></param>
251 /// <param name="type"></param>
252 /// <param name="data"></param></param>
253 /// <param name="tempFile"></param>
254 public void HandleUDPUploadRequest(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type,
255 byte[] data, bool storeLocal, bool tempFile)
256 {
257 // Console.WriteLine("asset upload of " + assetID);
258 AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
259
260 AgentAssetTransactions.AssetXferUploader uploader = transactions.RequestXferUploader(transaction);
261 if (uploader != null)
262 {
263
264 if (uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal, tempFile))
265 {
266
267 }
268 }
269 }
270
271 /// <summary>
272 /// Handle asset transfer data packets received in response to the asset upload request in
273 /// HandleUDPUploadRequest()
274 /// </summary>
275 /// <param name="remoteClient"></param>
276 /// <param name="xferID"></param>
277 /// <param name="packetID"></param>
278 /// <param name="data"></param>
279 public void HandleXfer(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data)
280 {
281 AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
282
283 transactions.HandleXfer(xferID, packetID, data);
284 }
285 }
286} \ No newline at end of file