aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/AgentAssetsTransactions.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/AgentAssetsTransactions.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/AgentAssetsTransactions.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/AgentAssetsTransactions.cs408
1 files changed, 0 insertions, 408 deletions
diff --git a/OpenSim/Region/Environment/Modules/AgentAssetsTransactions.cs b/OpenSim/Region/Environment/Modules/AgentAssetsTransactions.cs
deleted file mode 100644
index 9fa173d..0000000
--- a/OpenSim/Region/Environment/Modules/AgentAssetsTransactions.cs
+++ /dev/null
@@ -1,408 +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
28using System;
29using System.Collections.Generic;
30using System.IO;
31using libsecondlife;
32using libsecondlife.Packets;
33using OpenSim.Framework;
34using OpenSim.Framework.Communications.Cache;
35
36namespace OpenSim.Region.Environment.Modules
37{
38
39 /// <summary>
40 /// Manage asset transactions for a single agent.
41 /// </summary>
42 public class AgentAssetTransactions
43 {
44 //private static readonly log4net.ILog m_log
45 // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
46
47 // Fields
48 public LLUUID UserID;
49 public Dictionary<LLUUID, AssetXferUploader> XferUploaders = new Dictionary<LLUUID, AssetXferUploader>();
50 public AgentAssetTransactionsManager Manager;
51 private bool m_dumpAssetsToFile;
52
53 // Methods
54 public AgentAssetTransactions(LLUUID agentID, AgentAssetTransactionsManager manager, bool dumpAssetsToFile)
55 {
56 UserID = agentID;
57 Manager = manager;
58 m_dumpAssetsToFile = dumpAssetsToFile;
59 }
60
61 public AssetXferUploader RequestXferUploader(LLUUID transactionID)
62 {
63 if (!XferUploaders.ContainsKey(transactionID))
64 {
65 AssetXferUploader uploader = new AssetXferUploader(this, m_dumpAssetsToFile);
66
67 lock (XferUploaders)
68 {
69 XferUploaders.Add(transactionID, uploader);
70 }
71
72 return uploader;
73 }
74 return null;
75 }
76
77 public void HandleXfer(ulong xferID, uint packetID, byte[] data)
78 {
79 // AssetXferUploader uploaderFound = null;
80
81 lock (XferUploaders)
82 {
83 foreach (AssetXferUploader uploader in XferUploaders.Values)
84 {
85 if (uploader.XferID == xferID)
86 {
87 uploader.HandleXferPacket(xferID, packetID, data);
88 break;
89 }
90 }
91 }
92 }
93
94 public void RequestCreateInventoryItem(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID,
95 uint callbackID, string description, string name, sbyte invType,
96 sbyte type, byte wearableType, uint nextOwnerMask)
97 {
98 if (XferUploaders.ContainsKey(transactionID))
99 {
100 XferUploaders[transactionID].RequestCreateInventoryItem(remoteClient, transactionID, folderID,
101 callbackID, description, name, invType, type,
102 wearableType, nextOwnerMask);
103 }
104 }
105
106 public void RequestUpdateInventoryItem(IClientAPI remoteClient, LLUUID transactionID,
107 InventoryItemBase item)
108 {
109 if (XferUploaders.ContainsKey(transactionID))
110 {
111 XferUploaders[transactionID].RequestUpdateInventoryItem(remoteClient, transactionID, item);
112 }
113 }
114
115 /// <summary>
116 /// Get an uploaded asset. If the data is successfully retrieved, the transaction will be removed.
117 /// </summary>
118 /// <param name="transactionID"></param>
119 /// <returns>The asset if the upload has completed, null if it has not.</returns>
120 public AssetBase GetTransactionAsset(LLUUID transactionID)
121 {
122 if (XferUploaders.ContainsKey(transactionID))
123 {
124 AssetXferUploader uploader = XferUploaders[transactionID];
125 AssetBase asset = uploader.GetAssetData();
126
127 lock (XferUploaders)
128 {
129 XferUploaders.Remove(transactionID);
130 }
131
132 return asset;
133 }
134
135 return null;
136 }
137
138 // Nested Types
139 public class AssetXferUploader
140 {
141 // Fields
142 public bool AddToInventory;
143 public AssetBase Asset;
144 public LLUUID InventFolder = LLUUID.Zero;
145 private IClientAPI ourClient;
146 public LLUUID TransactionID = LLUUID.Zero;
147 public bool UploadComplete;
148 public ulong XferID;
149 private string m_name = String.Empty;
150 private string m_description = String.Empty;
151 private sbyte type = 0;
152 private sbyte invType = 0;
153 private byte wearableType = 0;
154 private uint nextPerm = 0;
155 private bool m_finished = false;
156 private bool m_createItem = false;
157 private AgentAssetTransactions m_userTransactions;
158 private bool m_storeLocal;
159 private bool m_dumpAssetToFile;
160
161 public AssetXferUploader(AgentAssetTransactions transactions, bool dumpAssetToFile)
162 {
163 m_userTransactions = transactions;
164 m_dumpAssetToFile = dumpAssetToFile;
165 }
166
167 /// <summary>
168 /// Process transfer data received from the client.
169 /// </summary>
170 /// <param name="xferID"></param>
171 /// <param name="packetID"></param>
172 /// <param name="data"></param>
173 /// <returns>True if the transfer is complete, false otherwise or if the xferID was not valid</returns>
174 public bool HandleXferPacket(ulong xferID, uint packetID, byte[] data)
175 {
176 if (XferID == xferID)
177 {
178 if (Asset.Data.Length > 1)
179 {
180 byte[] destinationArray = new byte[Asset.Data.Length + data.Length];
181 Array.Copy(Asset.Data, 0, destinationArray, 0, Asset.Data.Length);
182 Array.Copy(data, 0, destinationArray, Asset.Data.Length, data.Length);
183 Asset.Data = destinationArray;
184 }
185 else
186 {
187 byte[] buffer2 = new byte[data.Length - 4];
188 Array.Copy(data, 4, buffer2, 0, data.Length - 4);
189 Asset.Data = buffer2;
190 }
191 ConfirmXferPacketPacket newPack = new ConfirmXferPacketPacket();
192 newPack.XferID.ID = xferID;
193 newPack.XferID.Packet = packetID;
194 ourClient.OutPacket(newPack, ThrottleOutPacketType.Asset);
195 if ((packetID & 0x80000000) != 0)
196 {
197 SendCompleteMessage();
198 return true;
199 }
200 }
201
202 return false;
203 }
204
205 /// <summary>
206 /// Initialise asset transfer from the client
207 /// </summary>
208 /// <param name="xferID"></param>
209 /// <param name="packetID"></param>
210 /// <param name="data"></param>
211 /// <returns>True if the transfer is complete, false otherwise</returns>
212 public bool Initialise(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data,
213 bool storeLocal, bool tempFile)
214 {
215 ourClient = remoteClient;
216 Asset = new AssetBase();
217 Asset.FullID = assetID;
218 Asset.InvType = type;
219 Asset.Type = type;
220 Asset.Data = data;
221 Asset.Name = "blank";
222 Asset.Description = "empty";
223 Asset.Local = storeLocal;
224 Asset.Temporary = tempFile;
225
226 TransactionID = transaction;
227 m_storeLocal = storeLocal;
228 if (Asset.Data.Length > 2)
229 {
230 SendCompleteMessage();
231 return true;
232 }
233 else
234 {
235 RequestStartXfer();
236 }
237
238 return false;
239 }
240
241 protected void RequestStartXfer()
242 {
243 UploadComplete = false;
244 XferID = Util.GetNextXferID();
245 RequestXferPacket newPack = new RequestXferPacket();
246 newPack.XferID.ID = XferID;
247 newPack.XferID.VFileType = Asset.Type;
248 newPack.XferID.VFileID = Asset.FullID;
249 newPack.XferID.FilePath = 0;
250 newPack.XferID.Filename = new byte[0];
251 ourClient.OutPacket(newPack, ThrottleOutPacketType.Asset);
252 }
253
254 protected void SendCompleteMessage()
255 {
256 UploadComplete = true;
257 AssetUploadCompletePacket newPack = new AssetUploadCompletePacket();
258 newPack.AssetBlock.Type = Asset.Type;
259 newPack.AssetBlock.Success = true;
260 newPack.AssetBlock.UUID = Asset.FullID;
261 ourClient.OutPacket(newPack, ThrottleOutPacketType.Asset);
262 m_finished = true;
263 if (m_createItem)
264 {
265 DoCreateItem();
266 }
267 else if (m_storeLocal)
268 {
269 m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset);
270 }
271
272 // Console.WriteLine("upload complete "+ this.TransactionID);
273
274 if (m_dumpAssetToFile)
275 {
276 DateTime now = DateTime.Now;
277 string filename =
278 String.Format("{6}_{7}_{0:d2}{1:d2}{2:d2}_{3:d2}{4:d2}{5:d2}.dat", now.Year, now.Month, now.Day,
279 now.Hour, now.Minute, now.Second, Asset.Name, Asset.Type);
280 SaveAssetToFile(filename, Asset.Data);
281 }
282 }
283
284 ///Left this in and commented in case there are unforseen issues
285 //private void SaveAssetToFile(string filename, byte[] data)
286 //{
287 // FileStream fs = File.Create(filename);
288 // BinaryWriter bw = new BinaryWriter(fs);
289 // bw.Write(data);
290 // bw.Close();
291 // fs.Close();
292 //}
293 private void SaveAssetToFile(string filename, byte[] data)
294 {
295 string assetPath = "UserAssets";
296 if (!Directory.Exists(assetPath))
297 {
298 Directory.CreateDirectory(assetPath);
299 }
300 FileStream fs = File.Create(Path.Combine(assetPath, filename));
301 BinaryWriter bw = new BinaryWriter(fs);
302 bw.Write(data);
303 bw.Close();
304 fs.Close();
305 }
306
307 public void RequestCreateInventoryItem(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID,
308 uint callbackID, string description, string name, sbyte invType,
309 sbyte type, byte wearableType, uint nextOwnerMask)
310 {
311 if (TransactionID == transactionID)
312 {
313 InventFolder = folderID;
314 m_name = name;
315 m_description = description;
316 this.type = type;
317 this.invType = invType;
318 this.wearableType = wearableType;
319 nextPerm = nextOwnerMask;
320 Asset.Name = name;
321 Asset.Description = description;
322 Asset.Type = type;
323 Asset.InvType = invType;
324 m_createItem = true;
325 if (m_finished)
326 {
327 DoCreateItem();
328 }
329 }
330 }
331
332 public void RequestUpdateInventoryItem(IClientAPI remoteClient, LLUUID transactionID,
333 InventoryItemBase item)
334 {
335 if (TransactionID == transactionID)
336 {
337 CachedUserInfo userInfo =
338 m_userTransactions.Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails(
339 remoteClient.AgentId);
340
341 if (userInfo != null)
342 {
343 LLUUID assetID = LLUUID.Combine(transactionID, remoteClient.SecureSessionId);
344
345 AssetBase asset
346 = m_userTransactions.Manager.MyScene.CommsManager.AssetCache.GetAsset(
347 assetID, (item.AssetType == (int) AssetType.Texture ? true : false));
348
349 if (asset == null)
350 {
351 asset = m_userTransactions.GetTransactionAsset(transactionID);
352 }
353
354 if (asset != null && asset.FullID == assetID)
355 {
356 asset.Name = item.Name;
357 asset.Description = item.Description;
358 asset.InvType = (sbyte) item.InvType;
359 asset.Type = (sbyte) item.AssetType;
360 item.AssetID = asset.FullID;
361
362 m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset);
363 }
364
365 userInfo.UpdateItem(remoteClient.AgentId, item);
366 }
367 }
368 }
369
370 private void DoCreateItem()
371 {
372 //really need to fix this call, if lbsa71 saw this he would die.
373 m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset);
374 CachedUserInfo userInfo =
375 m_userTransactions.Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails(ourClient.AgentId);
376 if (userInfo != null)
377 {
378 InventoryItemBase item = new InventoryItemBase();
379 item.Owner = ourClient.AgentId;
380 item.Creator = ourClient.AgentId;
381 item.ID = LLUUID.Random();
382 item.AssetID = Asset.FullID;
383 item.Description = m_description;
384 item.Name = m_name;
385 item.AssetType = type;
386 item.InvType = invType;
387 item.Folder = InventFolder;
388 item.BasePermissions = 2147483647;
389 item.CurrentPermissions = 2147483647;
390 item.NextPermissions = nextPerm;
391 item.Flags = (uint)wearableType;
392
393 userInfo.AddItem(ourClient.AgentId, item);
394 ourClient.SendInventoryItemCreateUpdate(item);
395 }
396 }
397
398 public AssetBase GetAssetData()
399 {
400 if (m_finished)
401 {
402 return Asset;
403 }
404 return null;
405 }
406 }
407 }
408}