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