aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetTransactionsManager.cs2
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetsTransactions.cs284
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetXferUploader.cs311
3 files changed, 312 insertions, 285 deletions
diff --git a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetTransactionsManager.cs b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetTransactionsManager.cs
index 69fdc01..8d422aa 100644
--- a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetTransactionsManager.cs
+++ b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetTransactionsManager.cs
@@ -202,7 +202,7 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction
202 //Console.WriteLine("asset upload of " + assetID); 202 //Console.WriteLine("asset upload of " + assetID);
203 AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); 203 AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
204 204
205 AgentAssetTransactions.AssetXferUploader uploader = transactions.RequestXferUploader(transaction); 205 AssetXferUploader uploader = transactions.RequestXferUploader(transaction);
206 if (uploader != null) 206 if (uploader != null)
207 { 207 {
208 uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal, tempFile); 208 uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal, tempFile);
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}
diff --git a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetXferUploader.cs b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetXferUploader.cs
new file mode 100644
index 0000000..5edfe5d
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetXferUploader.cs
@@ -0,0 +1,311 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.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.IO;
30using System.Reflection;
31using log4net;
32using OpenMetaverse;
33using OpenMetaverse.Packets;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications.Cache;
36using OpenSim.Region.Environment.Scenes;
37
38namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction
39{
40 public class AssetXferUploader
41 {
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43
44 public bool AddToInventory;
45 public AssetBase Asset;
46 public UUID InventFolder = UUID.Zero;
47 private sbyte invType = 0;
48 private bool m_createItem = false;
49 private string m_description = String.Empty;
50 private bool m_dumpAssetToFile;
51 private bool m_finished = false;
52 private string m_name = String.Empty;
53 private bool m_storeLocal;
54 private AgentAssetTransactions m_userTransactions;
55 private uint nextPerm = 0;
56 private IClientAPI ourClient;
57 public UUID TransactionID = UUID.Zero;
58 private sbyte type = 0;
59 public bool UploadComplete;
60 private byte wearableType = 0;
61 public ulong XferID;
62
63 public AssetXferUploader(AgentAssetTransactions transactions, bool dumpAssetToFile)
64 {
65 m_userTransactions = transactions;
66 m_dumpAssetToFile = dumpAssetToFile;
67 }
68
69 /// <summary>
70 /// Process transfer data received from the client.
71 /// </summary>
72 /// <param name="xferID"></param>
73 /// <param name="packetID"></param>
74 /// <param name="data"></param>
75 /// <returns>True if the transfer is complete, false otherwise or if the xferID was not valid</returns>
76 public bool HandleXferPacket(ulong xferID, uint packetID, byte[] data)
77 {
78 if (XferID == xferID)
79 {
80 if (Asset.Data.Length > 1)
81 {
82 byte[] destinationArray = new byte[Asset.Data.Length + data.Length];
83 Array.Copy(Asset.Data, 0, destinationArray, 0, Asset.Data.Length);
84 Array.Copy(data, 0, destinationArray, Asset.Data.Length, data.Length);
85 Asset.Data = destinationArray;
86 }
87 else
88 {
89 byte[] buffer2 = new byte[data.Length - 4];
90 Array.Copy(data, 4, buffer2, 0, data.Length - 4);
91 Asset.Data = buffer2;
92 }
93
94 ourClient.SendConfirmXfer(xferID, packetID);
95
96 if ((packetID & 0x80000000) != 0)
97 {
98 SendCompleteMessage();
99 return true;
100 }
101 }
102
103 return false;
104 }
105
106 /// <summary>
107 /// Initialise asset transfer from the client
108 /// </summary>
109 /// <param name="xferID"></param>
110 /// <param name="packetID"></param>
111 /// <param name="data"></param>
112 /// <returns>True if the transfer is complete, false otherwise</returns>
113 public bool Initialise(IClientAPI remoteClient, UUID assetID, UUID transaction, sbyte type, byte[] data,
114 bool storeLocal, bool tempFile)
115 {
116 ourClient = remoteClient;
117 Asset = new AssetBase();
118 Asset.FullID = assetID;
119 Asset.Type = type;
120 Asset.Data = data;
121 Asset.Name = "blank";
122 Asset.Description = "empty";
123 Asset.Local = storeLocal;
124 Asset.Temporary = tempFile;
125
126 TransactionID = transaction;
127 m_storeLocal = storeLocal;
128
129 if (Asset.Data.Length > 2)
130 {
131 SendCompleteMessage();
132 return true;
133 }
134 else
135 {
136 RequestStartXfer();
137 }
138
139 return false;
140 }
141
142 protected void RequestStartXfer()
143 {
144 UploadComplete = false;
145 XferID = Util.GetNextXferID();
146 ourClient.SendXferRequest(XferID, Asset.Type, Asset.FullID, 0, new byte[0]);
147 }
148
149 protected void SendCompleteMessage()
150 {
151 UploadComplete = true;
152
153 ourClient.SendAssetUploadCompleteMessage(Asset.Type, true, Asset.FullID);
154
155 m_finished = true;
156 if (m_createItem)
157 {
158 DoCreateItem();
159 }
160 else if (m_storeLocal)
161 {
162 m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset);
163 }
164
165 m_log.DebugFormat("[ASSET TRANSACTIONS]: Uploaded asset data for transaction {0}", TransactionID);
166
167 if (m_dumpAssetToFile)
168 {
169 DateTime now = DateTime.Now;
170 string filename =
171 String.Format("{6}_{7}_{0:d2}{1:d2}{2:d2}_{3:d2}{4:d2}{5:d2}.dat", now.Year, now.Month, now.Day,
172 now.Hour, now.Minute, now.Second, Asset.Name, Asset.Type);
173 SaveAssetToFile(filename, Asset.Data);
174 }
175 }
176
177 private void SaveAssetToFile(string filename, byte[] data)
178 {
179 string assetPath = "UserAssets";
180 if (!Directory.Exists(assetPath))
181 {
182 Directory.CreateDirectory(assetPath);
183 }
184 FileStream fs = File.Create(Path.Combine(assetPath, filename));
185 BinaryWriter bw = new BinaryWriter(fs);
186 bw.Write(data);
187 bw.Close();
188 fs.Close();
189 }
190
191 public void RequestCreateInventoryItem(IClientAPI remoteClient, UUID transactionID, UUID folderID,
192 uint callbackID, string description, string name, sbyte invType,
193 sbyte type, byte wearableType, uint nextOwnerMask)
194 {
195 if (TransactionID == transactionID)
196 {
197 InventFolder = folderID;
198 m_name = name;
199 m_description = description;
200 this.type = type;
201 this.invType = invType;
202 this.wearableType = wearableType;
203 nextPerm = nextOwnerMask;
204 Asset.Name = name;
205 Asset.Description = description;
206 Asset.Type = type;
207 m_createItem = true;
208
209 if (m_finished)
210 {
211 DoCreateItem();
212 }
213 }
214 }
215
216 public void RequestUpdateInventoryItem(IClientAPI remoteClient, UUID transactionID,
217 InventoryItemBase item)
218 {
219 if (TransactionID == transactionID)
220 {
221 CachedUserInfo userInfo =
222 m_userTransactions.Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails(
223 remoteClient.AgentId);
224
225 if (userInfo != null)
226 {
227 UUID assetID = UUID.Combine(transactionID, remoteClient.SecureSessionId);
228
229 AssetBase asset
230 = m_userTransactions.Manager.MyScene.CommsManager.AssetCache.GetAsset(
231 assetID, (item.AssetType == (int) AssetType.Texture ? true : false));
232
233 if (asset == null)
234 {
235 asset = m_userTransactions.GetTransactionAsset(transactionID);
236 }
237
238 if (asset != null && asset.FullID == assetID)
239 {
240 // Assets never get updated, new ones get created
241 asset.FullID = UUID.Random();
242 asset.Name = item.Name;
243 asset.Description = item.Description;
244 asset.Type = (sbyte) item.AssetType;
245 item.AssetID = asset.FullID;
246
247 m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset);
248 }
249
250 userInfo.UpdateItem(item);
251 }
252 }
253 }
254
255 public void RequestUpdateTaskInventoryItem(
256 IClientAPI remoteClient, SceneObjectPart part, UUID transactionID, TaskInventoryItem item)
257 {
258 m_log.DebugFormat(
259 "[ASSET TRANSACTIONS]: Updating task item {0} in {1} with asset in transaction {2}",
260 item.Name, part.Name, transactionID);
261
262 Asset.Name = item.Name;
263 Asset.Description = item.Description;
264 Asset.Type = (sbyte) item.Type;
265 item.AssetID = Asset.FullID;
266
267 m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset);
268
269 if (part.UpdateInventoryItem(item))
270 part.GetProperties(remoteClient);
271 }
272
273 private void DoCreateItem()
274 {
275 //really need to fix this call, if lbsa71 saw this he would die.
276 m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset);
277 CachedUserInfo userInfo =
278 m_userTransactions.Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails(ourClient.AgentId);
279 if (userInfo != null)
280 {
281 InventoryItemBase item = new InventoryItemBase();
282 item.Owner = ourClient.AgentId;
283 item.Creator = ourClient.AgentId;
284 item.ID = UUID.Random();
285 item.AssetID = Asset.FullID;
286 item.Description = m_description;
287 item.Name = m_name;
288 item.AssetType = type;
289 item.InvType = invType;
290 item.Folder = InventFolder;
291 item.BasePermissions = 0x7fffffff;
292 item.CurrentPermissions = 0x7fffffff;
293 item.EveryOnePermissions=0;
294 item.NextPermissions = nextPerm;
295 item.Flags = (uint) wearableType;
296
297 userInfo.AddItem(item);
298 ourClient.SendInventoryItemCreateUpdate(item);
299 }
300 }
301
302 public AssetBase GetAssetData()
303 {
304 if (m_finished)
305 {
306 return Asset;
307 }
308 return null;
309 }
310 }
311}