aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.RegionServer/AgentAssetUpload.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/OpenSim.RegionServer/AgentAssetUpload.cs')
-rw-r--r--OpenSim/OpenSim.RegionServer/AgentAssetUpload.cs259
1 files changed, 0 insertions, 259 deletions
diff --git a/OpenSim/OpenSim.RegionServer/AgentAssetUpload.cs b/OpenSim/OpenSim.RegionServer/AgentAssetUpload.cs
deleted file mode 100644
index 65ccffd..0000000
--- a/OpenSim/OpenSim.RegionServer/AgentAssetUpload.cs
+++ /dev/null
@@ -1,259 +0,0 @@
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.Utilities;
34using libsecondlife;
35using libsecondlife.Packets;
36
37namespace OpenSim
38{
39 public class AgentAssetUpload
40 {
41 private Dictionary<LLUUID, AssetTransaction> transactions = new Dictionary<LLUUID, AssetTransaction>();
42 private ClientView ourClient;
43 private AssetCache m_assetCache;
44 private InventoryCache m_inventoryCache;
45
46 public AgentAssetUpload(ClientView client, AssetCache assetCache, InventoryCache inventoryCache)
47 {
48 this.ourClient = client;
49 m_assetCache = assetCache;
50 m_inventoryCache = inventoryCache;
51 }
52
53 public void AddUpload(LLUUID transactionID, AssetBase asset)
54 {
55 AssetTransaction upload = new AssetTransaction();
56 lock (this.transactions)
57 {
58 upload.Asset = asset;
59 upload.TransactionID = transactionID;
60 this.transactions.Add(transactionID, upload);
61 }
62 if (upload.Asset.Data.Length > 2)
63 {
64 //is complete
65 upload.UploadComplete = true;
66 AssetUploadCompletePacket response = new AssetUploadCompletePacket();
67 response.AssetBlock.Type = asset.Type;
68 response.AssetBlock.Success = true;
69 response.AssetBlock.UUID = transactionID.Combine(this.ourClient.SecureSessionID);
70 this.ourClient.OutPacket(response);
71 m_assetCache.AddAsset(asset);
72 }
73 else
74 {
75 upload.UploadComplete = false;
76 upload.XferID = Util.GetNextXferID();
77 RequestXferPacket xfer = new RequestXferPacket();
78 xfer.XferID.ID = upload.XferID;
79 xfer.XferID.VFileType = upload.Asset.Type;
80 xfer.XferID.VFileID = transactionID.Combine(this.ourClient.SecureSessionID);
81 xfer.XferID.FilePath = 0;
82 xfer.XferID.Filename = new byte[0];
83 this.ourClient.OutPacket(xfer);
84 }
85
86 }
87
88 public AssetBase GetUpload(LLUUID transactionID)
89 {
90 if (this.transactions.ContainsKey(transactionID))
91 {
92 return this.transactions[transactionID].Asset;
93 }
94
95 return null;
96 }
97
98 public void HandleUploadPacket(AssetUploadRequestPacket pack, LLUUID assetID)
99 {
100 // Console.Write("asset upload request , type = " + pack.AssetBlock.Type.ToString());
101 AssetBase asset = null;
102 if (pack.AssetBlock.Type == 0)
103 {
104
105 //first packet for transaction
106 asset = new AssetBase();
107 asset.FullID = assetID;
108 asset.Type = pack.AssetBlock.Type;
109 asset.InvType = asset.Type;
110 asset.Name = "UploadedTexture" + Util.RandomClass.Next(1, 1000).ToString("000");
111 asset.Data = pack.AssetBlock.AssetData;
112
113
114 }
115 else if (pack.AssetBlock.Type == 13 | pack.AssetBlock.Type == 5 | pack.AssetBlock.Type == 7)
116 {
117
118 asset = new AssetBase();
119 asset.FullID = assetID;
120 // Console.WriteLine("skin asset id is " + assetID.ToStringHyphenated());
121 asset.Type = pack.AssetBlock.Type;
122 asset.InvType = asset.Type;
123 asset.Name = "NewClothing" + Util.RandomClass.Next(1, 1000).ToString("000");
124 asset.Data = pack.AssetBlock.AssetData;
125
126
127 }
128
129 if (asset != null)
130 {
131 this.AddUpload(pack.AssetBlock.TransactionID, asset);
132 }
133 else
134 {
135
136 //currently we don't support this asset type
137 //so lets just tell the client that the upload is complete
138 AssetUploadCompletePacket response = new AssetUploadCompletePacket();
139 response.AssetBlock.Type = pack.AssetBlock.Type;
140 response.AssetBlock.Success = true;
141 response.AssetBlock.UUID = pack.AssetBlock.TransactionID.Combine(this.ourClient.SecureSessionID);
142 this.ourClient.OutPacket(response);
143 }
144
145 }
146
147 #region Xfer packet system for larger uploads
148
149 public void HandleXferPacket(SendXferPacketPacket xferPacket)
150 {
151 lock (this.transactions)
152 {
153 foreach (AssetTransaction trans in this.transactions.Values)
154 {
155 if (trans.XferID == xferPacket.XferID.ID)
156 {
157 if (trans.Asset.Data.Length > 1)
158 {
159 byte[] newArray = new byte[trans.Asset.Data.Length + xferPacket.DataPacket.Data.Length];
160 Array.Copy(trans.Asset.Data, 0, newArray, 0, trans.Asset.Data.Length);
161 Array.Copy(xferPacket.DataPacket.Data, 0, newArray, trans.Asset.Data.Length, xferPacket.DataPacket.Data.Length);
162 trans.Asset.Data = newArray;
163 }
164 else
165 {
166 byte[] newArray = new byte[xferPacket.DataPacket.Data.Length - 4];
167 Array.Copy(xferPacket.DataPacket.Data, 4, newArray, 0, xferPacket.DataPacket.Data.Length - 4);
168 trans.Asset.Data = newArray;
169 }
170
171 if ((xferPacket.XferID.Packet & 2147483648) != 0)
172 {
173 //end of transfer
174 trans.UploadComplete = true;
175 AssetUploadCompletePacket response = new AssetUploadCompletePacket();
176 response.AssetBlock.Type = trans.Asset.Type;
177 response.AssetBlock.Success = true;
178 response.AssetBlock.UUID = trans.TransactionID.Combine(this.ourClient.SecureSessionID);
179 this.ourClient.OutPacket(response);
180
181 m_assetCache.AddAsset(trans.Asset);
182 //check if we should add it to inventory
183 if (trans.AddToInventory)
184 {
185 // m_assetCache.AddAsset(trans.Asset);
186 m_inventoryCache.AddNewInventoryItem(this.ourClient, trans.InventFolder, trans.Asset);
187 }
188
189
190 }
191 break;
192 }
193
194 }
195 }
196
197 ConfirmXferPacketPacket confirmXfer = new ConfirmXferPacketPacket();
198 confirmXfer.XferID.ID = xferPacket.XferID.ID;
199 confirmXfer.XferID.Packet = xferPacket.XferID.Packet;
200 this.ourClient.OutPacket(confirmXfer);
201 }
202
203 #endregion
204
205 public AssetBase AddUploadToAssetCache(LLUUID transactionID)
206 {
207 AssetBase asset = null;
208 if (this.transactions.ContainsKey(transactionID))
209 {
210 AssetTransaction trans = this.transactions[transactionID];
211 if (trans.UploadComplete)
212 {
213 m_assetCache.AddAsset(trans.Asset);
214 asset = trans.Asset;
215 }
216 }
217
218 return asset;
219 }
220
221 public void CreateInventoryItem(CreateInventoryItemPacket packet)
222 {
223 if (this.transactions.ContainsKey(packet.InventoryBlock.TransactionID))
224 {
225 AssetTransaction trans = this.transactions[packet.InventoryBlock.TransactionID];
226 trans.Asset.Description = Util.FieldToString(packet.InventoryBlock.Description);
227 trans.Asset.Name = Util.FieldToString(packet.InventoryBlock.Name);
228 trans.Asset.Type = packet.InventoryBlock.Type;
229 trans.Asset.InvType = packet.InventoryBlock.InvType;
230 if (trans.UploadComplete)
231 {
232 //already complete so we can add it to the inventory
233 //m_assetCache.AddAsset(trans.Asset);
234 m_inventoryCache.AddNewInventoryItem(this.ourClient, packet.InventoryBlock.FolderID, trans.Asset);
235 }
236 else
237 {
238 trans.AddToInventory = true;
239 trans.InventFolder = packet.InventoryBlock.FolderID;
240 }
241 }
242 }
243
244 private class AssetTransaction
245 {
246 public uint XferID;
247 public AssetBase Asset;
248 public bool AddToInventory;
249 public LLUUID InventFolder = LLUUID.Zero;
250 public bool UploadComplete = false;
251 public LLUUID TransactionID = LLUUID.Zero;
252
253 public AssetTransaction()
254 {
255
256 }
257 }
258 }
259}