aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetsTransactions.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetsTransactions.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetsTransactions.cs284
1 files changed, 0 insertions, 284 deletions
diff --git a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetsTransactions.cs b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetsTransactions.cs
index b32d199..2a91624 100644
--- a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetsTransactions.cs
+++ b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetsTransactions.cs
@@ -27,13 +27,8 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.IO;
31using System.Reflection;
32using log4net;
33using OpenMetaverse; 30using OpenMetaverse;
34using OpenMetaverse.Packets;
35using OpenSim.Framework; 31using OpenSim.Framework;
36using OpenSim.Framework.Communications.Cache;
37using OpenSim.Region.Environment.Scenes; 32using OpenSim.Region.Environment.Scenes;
38 33
39namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction 34namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction
@@ -143,284 +138,5 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction
143 138
144 return null; 139 return null;
145 } 140 }
146
147 // Nested Types
148
149 #region Nested type: AssetXferUploader
150
151 public class AssetXferUploader
152 {
153 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
154
155 // Fields
156 public bool AddToInventory;
157 public AssetBase Asset;
158 public UUID InventFolder = UUID.Zero;
159 private sbyte invType = 0;
160 private bool m_createItem = false;
161 private string m_description = String.Empty;
162 private bool m_dumpAssetToFile;
163 private bool m_finished = false;
164 private string m_name = String.Empty;
165 private bool m_storeLocal;
166 private AgentAssetTransactions m_userTransactions;
167 private uint nextPerm = 0;
168 private IClientAPI ourClient;
169 public UUID TransactionID = UUID.Zero;
170 private sbyte type = 0;
171 public bool UploadComplete;
172 private byte wearableType = 0;
173 public ulong XferID;
174
175 public AssetXferUploader(AgentAssetTransactions transactions, bool dumpAssetToFile)
176 {
177 m_userTransactions = transactions;
178 m_dumpAssetToFile = dumpAssetToFile;
179 }
180
181 /// <summary>
182 /// Process transfer data received from the client.
183 /// </summary>
184 /// <param name="xferID"></param>
185 /// <param name="packetID"></param>
186 /// <param name="data"></param>
187 /// <returns>True if the transfer is complete, false otherwise or if the xferID was not valid</returns>
188 public bool HandleXferPacket(ulong xferID, uint packetID, byte[] data)
189 {
190 if (XferID == xferID)
191 {
192 if (Asset.Data.Length > 1)
193 {
194 byte[] destinationArray = new byte[Asset.Data.Length + data.Length];
195 Array.Copy(Asset.Data, 0, destinationArray, 0, Asset.Data.Length);
196 Array.Copy(data, 0, destinationArray, Asset.Data.Length, data.Length);
197 Asset.Data = destinationArray;
198 }
199 else
200 {
201 byte[] buffer2 = new byte[data.Length - 4];
202 Array.Copy(data, 4, buffer2, 0, data.Length - 4);
203 Asset.Data = buffer2;
204 }
205
206 ourClient.SendConfirmXfer(xferID, packetID);
207
208 if ((packetID & 0x80000000) != 0)
209 {
210 SendCompleteMessage();
211 return true;
212 }
213 }
214
215 return false;
216 }
217
218 /// <summary>
219 /// Initialise asset transfer from the client
220 /// </summary>
221 /// <param name="xferID"></param>
222 /// <param name="packetID"></param>
223 /// <param name="data"></param>
224 /// <returns>True if the transfer is complete, false otherwise</returns>
225 public bool Initialise(IClientAPI remoteClient, UUID assetID, UUID transaction, sbyte type, byte[] data,
226 bool storeLocal, bool tempFile)
227 {
228 ourClient = remoteClient;
229 Asset = new AssetBase();
230 Asset.FullID = assetID;
231 Asset.Type = type;
232 Asset.Data = data;
233 Asset.Name = "blank";
234 Asset.Description = "empty";
235 Asset.Local = storeLocal;
236 Asset.Temporary = tempFile;
237
238 TransactionID = transaction;
239 m_storeLocal = storeLocal;
240
241 if (Asset.Data.Length > 2)
242 {
243 SendCompleteMessage();
244 return true;
245 }
246 else
247 {
248 RequestStartXfer();
249 }
250
251 return false;
252 }
253
254 protected void RequestStartXfer()
255 {
256 UploadComplete = false;
257 XferID = Util.GetNextXferID();
258 ourClient.SendXferRequest(XferID, Asset.Type, Asset.FullID, 0, new byte[0]);
259 }
260
261 protected void SendCompleteMessage()
262 {
263 UploadComplete = true;
264
265 ourClient.SendAssetUploadCompleteMessage(Asset.Type, true, Asset.FullID);
266
267 m_finished = true;
268 if (m_createItem)
269 {
270 DoCreateItem();
271 }
272 else if (m_storeLocal)
273 {
274 m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset);
275 }
276
277 m_log.DebugFormat("[ASSET TRANSACTIONS]: Uploaded asset data for transaction {0}", TransactionID);
278
279 if (m_dumpAssetToFile)
280 {
281 DateTime now = DateTime.Now;
282 string filename =
283 String.Format("{6}_{7}_{0:d2}{1:d2}{2:d2}_{3:d2}{4:d2}{5:d2}.dat", now.Year, now.Month, now.Day,
284 now.Hour, now.Minute, now.Second, Asset.Name, Asset.Type);
285 SaveAssetToFile(filename, Asset.Data);
286 }
287 }
288
289 private void SaveAssetToFile(string filename, byte[] data)
290 {
291 string assetPath = "UserAssets";
292 if (!Directory.Exists(assetPath))
293 {
294 Directory.CreateDirectory(assetPath);
295 }
296 FileStream fs = File.Create(Path.Combine(assetPath, filename));
297 BinaryWriter bw = new BinaryWriter(fs);
298 bw.Write(data);
299 bw.Close();
300 fs.Close();
301 }
302
303 public void RequestCreateInventoryItem(IClientAPI remoteClient, UUID transactionID, UUID folderID,
304 uint callbackID, string description, string name, sbyte invType,
305 sbyte type, byte wearableType, uint nextOwnerMask)
306 {
307 if (TransactionID == transactionID)
308 {
309 InventFolder = folderID;
310 m_name = name;
311 m_description = description;
312 this.type = type;
313 this.invType = invType;
314 this.wearableType = wearableType;
315 nextPerm = nextOwnerMask;
316 Asset.Name = name;
317 Asset.Description = description;
318 Asset.Type = type;
319 m_createItem = true;
320
321 if (m_finished)
322 {
323 DoCreateItem();
324 }
325 }
326 }
327
328 public void RequestUpdateInventoryItem(IClientAPI remoteClient, UUID transactionID,
329 InventoryItemBase item)
330 {
331 if (TransactionID == transactionID)
332 {
333 CachedUserInfo userInfo =
334 m_userTransactions.Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails(
335 remoteClient.AgentId);
336
337 if (userInfo != null)
338 {
339 UUID assetID = UUID.Combine(transactionID, remoteClient.SecureSessionId);
340
341 AssetBase asset
342 = m_userTransactions.Manager.MyScene.CommsManager.AssetCache.GetAsset(
343 assetID, (item.AssetType == (int) AssetType.Texture ? true : false));
344
345 if (asset == null)
346 {
347 asset = m_userTransactions.GetTransactionAsset(transactionID);
348 }
349
350 if (asset != null && asset.FullID == assetID)
351 {
352 // Assets never get updated, new ones get created
353 asset.FullID = UUID.Random();
354 asset.Name = item.Name;
355 asset.Description = item.Description;
356 asset.Type = (sbyte) item.AssetType;
357 item.AssetID = asset.FullID;
358
359 m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset);
360 }
361
362 userInfo.UpdateItem(item);
363 }
364 }
365 }
366
367 public void RequestUpdateTaskInventoryItem(
368 IClientAPI remoteClient, SceneObjectPart part, UUID transactionID, TaskInventoryItem item)
369 {
370 m_log.DebugFormat(
371 "[ASSET TRANSACTIONS]: Updating task item {0} in {1} with asset in transaction {2}",
372 item.Name, part.Name, transactionID);
373
374 Asset.Name = item.Name;
375 Asset.Description = item.Description;
376 Asset.Type = (sbyte) item.Type;
377 item.AssetID = Asset.FullID;
378
379 m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset);
380
381 if (part.UpdateInventoryItem(item))
382 part.GetProperties(remoteClient);
383 }
384
385 private void DoCreateItem()
386 {
387 //really need to fix this call, if lbsa71 saw this he would die.
388 m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset);
389 CachedUserInfo userInfo =
390 m_userTransactions.Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails(ourClient.AgentId);
391 if (userInfo != null)
392 {
393 InventoryItemBase item = new InventoryItemBase();
394 item.Owner = ourClient.AgentId;
395 item.Creator = ourClient.AgentId;
396 item.ID = UUID.Random();
397 item.AssetID = Asset.FullID;
398 item.Description = m_description;
399 item.Name = m_name;
400 item.AssetType = type;
401 item.InvType = invType;
402 item.Folder = InventFolder;
403 item.BasePermissions = 0x7fffffff;
404 item.CurrentPermissions = 0x7fffffff;
405 item.EveryOnePermissions=0;
406 item.NextPermissions = nextPerm;
407 item.Flags = (uint) wearableType;
408
409 userInfo.AddItem(item);
410 ourClient.SendInventoryItemCreateUpdate(item);
411 }
412 }
413
414 public AssetBase GetAssetData()
415 {
416 if (m_finished)
417 {
418 return Asset;
419 }
420 return null;
421 }
422 }
423
424 #endregion
425 } 141 }
426} 142}