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