aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/ClientView.AgentAssetUpload.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ClientStack/ClientView.AgentAssetUpload.cs358
1 files changed, 358 insertions, 0 deletions
diff --git a/OpenSim/Region/ClientStack/ClientView.AgentAssetUpload.cs b/OpenSim/Region/ClientStack/ClientView.AgentAssetUpload.cs
new file mode 100644
index 0000000..914c38a
--- /dev/null
+++ b/OpenSim/Region/ClientStack/ClientView.AgentAssetUpload.cs
@@ -0,0 +1,358 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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.Text;
31using OpenSim.Assets;
32using OpenSim.Framework.Types;
33using OpenSim.Framework.Interfaces;
34using OpenSim.Framework.Utilities;
35using OpenSim.Caches;
36using libsecondlife;
37using libsecondlife.Packets;
38
39namespace OpenSim
40{
41 partial class ClientView
42 {
43 public class AgentAssetUpload
44 {
45 private Dictionary<LLUUID, AssetTransaction> transactions = new Dictionary<LLUUID, AssetTransaction>();
46 private ClientView ourClient;
47 private AssetCache m_assetCache;
48 private InventoryCache m_inventoryCache;
49
50 public AgentAssetUpload(ClientView client, AssetCache assetCache, InventoryCache inventoryCache)
51 {
52 this.ourClient = client;
53 m_assetCache = assetCache;
54 m_inventoryCache = inventoryCache;
55 }
56
57 public void AddUpload(LLUUID transactionID, AssetBase asset)
58 {
59 AssetTransaction upload = new AssetTransaction();
60 lock (this.transactions)
61 {
62 upload.Asset = asset;
63 upload.TransactionID = transactionID;
64 this.transactions.Add(transactionID, upload);
65 }
66 if (upload.Asset.Data.Length > 2)
67 {
68 //is complete
69 upload.UploadComplete = true;
70 AssetUploadCompletePacket response = new AssetUploadCompletePacket();
71 response.AssetBlock.Type = asset.Type;
72 response.AssetBlock.Success = true;
73 response.AssetBlock.UUID = transactionID.Combine(this.ourClient.SecureSessionID);
74 this.ourClient.OutPacket(response);
75 m_assetCache.AddAsset(asset);
76 }
77 else
78 {
79 upload.UploadComplete = false;
80 upload.XferID = Util.GetNextXferID();
81 RequestXferPacket xfer = new RequestXferPacket();
82 xfer.XferID.ID = upload.XferID;
83 xfer.XferID.VFileType = upload.Asset.Type;
84 xfer.XferID.VFileID = transactionID.Combine(this.ourClient.SecureSessionID);
85 xfer.XferID.FilePath = 0;
86 xfer.XferID.Filename = new byte[0];
87 this.ourClient.OutPacket(xfer);
88 }
89
90 }
91
92 public AssetBase GetUpload(LLUUID transactionID)
93 {
94 if (this.transactions.ContainsKey(transactionID))
95 {
96 return this.transactions[transactionID].Asset;
97 }
98
99 return null;
100 }
101
102 public void HandleUploadPacket(AssetUploadRequestPacket pack, LLUUID assetID)
103 {
104 // Console.Write("asset upload request , type = " + pack.AssetBlock.Type.ToString());
105 AssetBase asset = null;
106 if (pack.AssetBlock.Type == 0)
107 {
108
109 //first packet for transaction
110 asset = new AssetBase();
111 asset.FullID = assetID;
112 asset.Type = pack.AssetBlock.Type;
113 asset.InvType = asset.Type;
114 asset.Name = "UploadedTexture" + Util.RandomClass.Next(1, 1000).ToString("000");
115 asset.Data = pack.AssetBlock.AssetData;
116
117
118 }
119 else if (pack.AssetBlock.Type == 13 | pack.AssetBlock.Type == 5 | pack.AssetBlock.Type == 7)
120 {
121
122 asset = new AssetBase();
123 asset.FullID = assetID;
124 // Console.WriteLine("skin asset id is " + assetID.ToStringHyphenated());
125 asset.Type = pack.AssetBlock.Type;
126 asset.InvType = asset.Type;
127 asset.Name = "NewClothing" + Util.RandomClass.Next(1, 1000).ToString("000");
128 asset.Data = pack.AssetBlock.AssetData;
129
130
131 }
132
133 if (asset != null)
134 {
135 this.AddUpload(pack.AssetBlock.TransactionID, asset);
136 }
137 else
138 {
139
140 //currently we don't support this asset type
141 //so lets just tell the client that the upload is complete
142 AssetUploadCompletePacket response = new AssetUploadCompletePacket();
143 response.AssetBlock.Type = pack.AssetBlock.Type;
144 response.AssetBlock.Success = true;
145 response.AssetBlock.UUID = pack.AssetBlock.TransactionID.Combine(this.ourClient.SecureSessionID);
146 this.ourClient.OutPacket(response);
147 }
148
149 }
150
151 #region Xfer packet system for larger uploads
152
153 public void HandleXferPacket(SendXferPacketPacket xferPacket)
154 {
155 lock (this.transactions)
156 {
157 foreach (AssetTransaction trans in this.transactions.Values)
158 {
159 if (trans.XferID == xferPacket.XferID.ID)
160 {
161 if (trans.Asset.Data.Length > 1)
162 {
163 byte[] newArray = new byte[trans.Asset.Data.Length + xferPacket.DataPacket.Data.Length];
164 Array.Copy(trans.Asset.Data, 0, newArray, 0, trans.Asset.Data.Length);
165 Array.Copy(xferPacket.DataPacket.Data, 0, newArray, trans.Asset.Data.Length, xferPacket.DataPacket.Data.Length);
166 trans.Asset.Data = newArray;
167 }
168 else
169 {
170 byte[] newArray = new byte[xferPacket.DataPacket.Data.Length - 4];
171 Array.Copy(xferPacket.DataPacket.Data, 4, newArray, 0, xferPacket.DataPacket.Data.Length - 4);
172 trans.Asset.Data = newArray;
173 }
174
175 if ((xferPacket.XferID.Packet & 2147483648) != 0)
176 {
177 //end of transfer
178 trans.UploadComplete = true;
179 AssetUploadCompletePacket response = new AssetUploadCompletePacket();
180 response.AssetBlock.Type = trans.Asset.Type;
181 response.AssetBlock.Success = true;
182 response.AssetBlock.UUID = trans.TransactionID.Combine(this.ourClient.SecureSessionID);
183 this.ourClient.OutPacket(response);
184
185 m_assetCache.AddAsset(trans.Asset);
186 //check if we should add it to inventory
187 if (trans.AddToInventory)
188 {
189 // m_assetCache.AddAsset(trans.Asset);
190 m_inventoryCache.AddNewInventoryItem(this.ourClient, trans.InventFolder, trans.Asset);
191 }
192
193
194 }
195 break;
196 }
197
198 }
199 }
200
201 ConfirmXferPacketPacket confirmXfer = new ConfirmXferPacketPacket();
202 confirmXfer.XferID.ID = xferPacket.XferID.ID;
203 confirmXfer.XferID.Packet = xferPacket.XferID.Packet;
204 this.ourClient.OutPacket(confirmXfer);
205 }
206
207 #endregion
208
209 public AssetBase AddUploadToAssetCache(LLUUID transactionID)
210 {
211 AssetBase asset = null;
212 if (this.transactions.ContainsKey(transactionID))
213 {
214 AssetTransaction trans = this.transactions[transactionID];
215 if (trans.UploadComplete)
216 {
217 m_assetCache.AddAsset(trans.Asset);
218 asset = trans.Asset;
219 }
220 }
221
222 return asset;
223 }
224
225 public void CreateInventoryItem(CreateInventoryItemPacket packet)
226 {
227 if (this.transactions.ContainsKey(packet.InventoryBlock.TransactionID))
228 {
229 AssetTransaction trans = this.transactions[packet.InventoryBlock.TransactionID];
230 trans.Asset.Description = Util.FieldToString(packet.InventoryBlock.Description);
231 trans.Asset.Name = Util.FieldToString(packet.InventoryBlock.Name);
232 trans.Asset.Type = packet.InventoryBlock.Type;
233 trans.Asset.InvType = packet.InventoryBlock.InvType;
234 if (trans.UploadComplete)
235 {
236 //already complete so we can add it to the inventory
237 //m_assetCache.AddAsset(trans.Asset);
238 m_inventoryCache.AddNewInventoryItem(this.ourClient, packet.InventoryBlock.FolderID, trans.Asset);
239 }
240 else
241 {
242 trans.AddToInventory = true;
243 trans.InventFolder = packet.InventoryBlock.FolderID;
244 }
245 }
246 }
247
248 private class AssetTransaction
249 {
250 public uint XferID;
251 public AssetBase Asset;
252 public bool AddToInventory;
253 public LLUUID InventFolder = LLUUID.Zero;
254 public bool UploadComplete = false;
255 public LLUUID TransactionID = LLUUID.Zero;
256
257 public AssetTransaction()
258 {
259
260 }
261 }
262
263 //new class , not currently used.
264 public class AssetXferUploader
265 {
266 private IClientAPI ourClient;
267
268 public bool UploadComplete = false;
269
270 public bool AddToInventory;
271 public LLUUID InventFolder = LLUUID.Zero;
272
273 public uint XferID;
274 public AssetBase Asset;
275 public LLUUID TransactionID = LLUUID.Zero;
276
277
278 public AssetXferUploader(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data)
279 {
280 ourClient = remoteClient;
281 Asset = new AssetBase();
282 Asset.FullID = assetID;
283 Asset.InvType = type;
284 Asset.Type = type;
285 Asset.Data = data;
286 Asset.Name = "blank";
287 Asset.Description = "empty";
288 TransactionID = transaction;
289
290 if (Asset.Data.Length > 2)
291 {
292 //data block should only have data in it, if there is no more data to be uploaded
293 this.SendCompleteMessage();
294 }
295 else
296 {
297 this.ReqestStartXfer();
298 }
299 }
300
301 protected void SendCompleteMessage()
302 {
303 UploadComplete = true;
304 AssetUploadCompletePacket response = new AssetUploadCompletePacket();
305 response.AssetBlock.Type = Asset.Type;
306 response.AssetBlock.Success = true;
307 response.AssetBlock.UUID = Asset.FullID;
308 this.ourClient.OutPacket(response);
309
310 //TODO trigger event
311 }
312
313 protected void ReqestStartXfer()
314 {
315 UploadComplete = false;
316 XferID = Util.GetNextXferID();
317 RequestXferPacket xfer = new RequestXferPacket();
318 xfer.XferID.ID = XferID;
319 xfer.XferID.VFileType = Asset.Type;
320 xfer.XferID.VFileID = Asset.FullID;
321 xfer.XferID.FilePath = 0;
322 xfer.XferID.Filename = new byte[0];
323 this.ourClient.OutPacket(xfer);
324 }
325
326 public void HandleXferPacket(uint xferID, uint packetID, byte[] data)
327 {
328 if (XferID == xferID)
329 {
330 if (Asset.Data.Length > 1)
331 {
332 byte[] newArray = new byte[Asset.Data.Length + data.Length];
333 Array.Copy(Asset.Data, 0, newArray, 0, Asset.Data.Length);
334 Array.Copy(data, 0, newArray, Asset.Data.Length, data.Length);
335 Asset.Data = newArray;
336 }
337 else
338 {
339 byte[] newArray = new byte[data.Length - 4];
340 Array.Copy(data, 4, newArray, 0, data.Length - 4);
341 Asset.Data = newArray;
342 }
343
344 ConfirmXferPacketPacket confirmXfer = new ConfirmXferPacketPacket();
345 confirmXfer.XferID.ID = xferID;
346 confirmXfer.XferID.Packet = packetID;
347 this.ourClient.OutPacket(confirmXfer);
348
349 if ((packetID & 2147483648) != 0)
350 {
351 this.SendCompleteMessage();
352 }
353 }
354 }
355 }
356 }
357 }
358}