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