diff options
Diffstat (limited to 'OpenSim/OpenSim.RegionServer/AgentAssetUpload.cs')
-rw-r--r-- | OpenSim/OpenSim.RegionServer/AgentAssetUpload.cs | 259 |
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 6781781..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 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using OpenSim.RegionServer.Assets; | ||
32 | using OpenSim.RegionServer.Client; | ||
33 | using OpenSim.Framework.Types; | ||
34 | using OpenSim.Framework.Utilities; | ||
35 | using libsecondlife; | ||
36 | using libsecondlife.Packets; | ||
37 | |||
38 | namespace OpenSim.RegionServer | ||
39 | { | ||
40 | public class AgentAssetUpload | ||
41 | { | ||
42 | private Dictionary<LLUUID, AssetTransaction> transactions = new Dictionary<LLUUID, AssetTransaction>(); | ||
43 | private ClientView ourClient; | ||
44 | private AssetCache m_assetCache; | ||
45 | private InventoryCache m_inventoryCache; | ||
46 | |||
47 | public AgentAssetUpload(ClientView client, AssetCache assetCache, InventoryCache inventoryCache) | ||
48 | { | ||
49 | this.ourClient = client; | ||
50 | m_assetCache = assetCache; | ||
51 | m_inventoryCache = inventoryCache; | ||
52 | } | ||
53 | |||
54 | public void AddUpload(LLUUID transactionID, AssetBase asset) | ||
55 | { | ||
56 | AssetTransaction upload = new AssetTransaction(); | ||
57 | lock (this.transactions) | ||
58 | { | ||
59 | upload.Asset = asset; | ||
60 | upload.TransactionID = transactionID; | ||
61 | this.transactions.Add(transactionID, upload); | ||
62 | } | ||
63 | if (upload.Asset.Data.Length > 2) | ||
64 | { | ||
65 | //is complete | ||
66 | upload.UploadComplete = true; | ||
67 | AssetUploadCompletePacket response = new AssetUploadCompletePacket(); | ||
68 | response.AssetBlock.Type = asset.Type; | ||
69 | response.AssetBlock.Success = true; | ||
70 | response.AssetBlock.UUID = transactionID.Combine(this.ourClient.SecureSessionID); | ||
71 | this.ourClient.OutPacket(response); | ||
72 | m_assetCache.AddAsset(asset); | ||
73 | } | ||
74 | else | ||
75 | { | ||
76 | upload.UploadComplete = false; | ||
77 | upload.XferID = Util.GetNextXferID(); | ||
78 | RequestXferPacket xfer = new RequestXferPacket(); | ||
79 | xfer.XferID.ID = upload.XferID; | ||
80 | xfer.XferID.VFileType = upload.Asset.Type; | ||
81 | xfer.XferID.VFileID = transactionID.Combine(this.ourClient.SecureSessionID); | ||
82 | xfer.XferID.FilePath = 0; | ||
83 | xfer.XferID.Filename = new byte[0]; | ||
84 | this.ourClient.OutPacket(xfer); | ||
85 | } | ||
86 | |||
87 | } | ||
88 | |||
89 | public AssetBase GetUpload(LLUUID transactionID) | ||
90 | { | ||
91 | if (this.transactions.ContainsKey(transactionID)) | ||
92 | { | ||
93 | return this.transactions[transactionID].Asset; | ||
94 | } | ||
95 | |||
96 | return null; | ||
97 | } | ||
98 | |||
99 | public void HandleUploadPacket(AssetUploadRequestPacket pack, LLUUID assetID) | ||
100 | { | ||
101 | // Console.Write("asset upload request , type = " + pack.AssetBlock.Type.ToString()); | ||
102 | AssetBase asset = null; | ||
103 | if (pack.AssetBlock.Type == 0) | ||
104 | { | ||
105 | |||
106 | //first packet for transaction | ||
107 | asset = new AssetBase(); | ||
108 | asset.FullID = assetID; | ||
109 | asset.Type = pack.AssetBlock.Type; | ||
110 | asset.InvType = asset.Type; | ||
111 | asset.Name = "UploadedTexture" + Util.RandomClass.Next(1, 1000).ToString("000"); | ||
112 | asset.Data = pack.AssetBlock.AssetData; | ||
113 | |||
114 | |||
115 | } | ||
116 | else if (pack.AssetBlock.Type == 13 | pack.AssetBlock.Type == 5 | pack.AssetBlock.Type == 7) | ||
117 | { | ||
118 | |||
119 | asset = new AssetBase(); | ||
120 | asset.FullID = assetID; | ||
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 | } | ||