aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/AgentAgentTransactionModule.cs244
-rw-r--r--OpenSim/Region/Environment/Modules/AgentAssetsTransactions.cs382
2 files changed, 626 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/AgentAgentTransactionModule.cs b/OpenSim/Region/Environment/Modules/AgentAgentTransactionModule.cs
new file mode 100644
index 0000000..2374964
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/AgentAgentTransactionModule.cs
@@ -0,0 +1,244 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using libsecondlife;
5using Nini.Config;
6using OpenSim.Framework;
7using OpenSim.Region.Environment.Interfaces;
8using OpenSim.Region.Environment.Scenes;
9
10namespace OpenSim.Region.Environment.Modules
11{
12 public class AgentAgentTransactionModule : IRegionModule, IAgentAssetTransactions
13 {
14 private Dictionary<LLUUID, Scene> RegisteredScenes = new Dictionary<LLUUID, Scene>();
15 private Scene m_scene = null;
16 private bool m_dumpAssetsToFile = false;
17
18 private AgentAssetTransactionsManager m_transactionManager;
19
20 public void Initialise(Scene scene, IConfigSource config)
21 {
22 if (!RegisteredScenes.ContainsKey(scene.RegionInfo.RegionID))
23 {
24 RegisteredScenes.Add(scene.RegionInfo.RegionID, scene);
25 scene.RegisterModuleInterface<IAgentAssetTransactions>(this);
26
27 scene.EventManager.OnNewClient += NewClient;
28
29 try
30 {
31 m_dumpAssetsToFile = config.Configs["StandAlone"].GetBoolean("dump_assets_to_file", false);
32 }
33 catch (Exception)
34 {
35 }
36 }
37
38 if (m_scene == null)
39 {
40 m_scene = scene;
41 m_transactionManager = new AgentAssetTransactionsManager(m_scene, m_dumpAssetsToFile);
42 }
43 }
44
45 public void PostInitialise()
46 {
47
48 }
49
50 public void Close()
51 {
52 }
53
54 public string Name
55 {
56 get { return "AgentTransactionModule"; }
57 }
58
59 public bool IsSharedModule
60 {
61 get { return true; }
62 }
63
64 public void NewClient(IClientAPI client)
65 {
66 client.OnAssetUploadRequest += m_transactionManager.HandleUDPUploadRequest;
67 client.OnXferReceive += m_transactionManager.HandleXfer;
68 }
69
70 public void HandleItemCreationFromTransaction(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID,
71 uint callbackID, string description, string name, sbyte invType,
72 sbyte type, byte wearableType, uint nextOwnerMask)
73 {
74 m_transactionManager.HandleItemCreationFromTransaction(remoteClient, transactionID, folderID, callbackID, description, name, invType, type, wearableType, nextOwnerMask);
75 }
76
77 public void HandleItemUpdateFromTransaction(IClientAPI remoteClient, LLUUID transactionID,
78 InventoryItemBase item)
79 {
80 m_transactionManager.HandleItemUpdateFromTransaction(remoteClient, transactionID, item);
81 }
82
83 public void RemoveAgentAssetTransactions(LLUUID userID)
84 {
85 m_transactionManager.RemoveAgentAssetTransactions(userID);
86 }
87 }
88
89 //should merge this classes and clean up
90 public class AgentAssetTransactionsManager
91 {
92 private static readonly log4net.ILog m_log
93 = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
94
95 // Fields
96 public Scene MyScene;
97
98 /// <summary>
99 /// Each agent has its own singleton collection of transactions
100 /// </summary>
101 private Dictionary<LLUUID, AgentAssetTransactions> AgentTransactions =
102 new Dictionary<LLUUID, AgentAssetTransactions>();
103
104 /// <summary>
105 /// Should we dump uploaded assets to the filesystem?
106 /// </summary>
107 private bool m_dumpAssetsToFile;
108
109 public AgentAssetTransactionsManager(Scene scene, bool dumpAssetsToFile)
110 {
111 MyScene = scene;
112 m_dumpAssetsToFile = dumpAssetsToFile;
113 }
114
115 /// <summary>
116 /// Get the collection of asset transactions for the given user. If one does not already exist, it
117 /// is created.
118 /// </summary>
119 /// <param name="userID"></param>
120 /// <returns></returns>
121 private AgentAssetTransactions GetUserTransactions(LLUUID userID)
122 {
123 lock (AgentTransactions)
124 {
125 if (!AgentTransactions.ContainsKey(userID))
126 {
127 AgentAssetTransactions transactions
128 = new AgentAssetTransactions(userID, this, m_dumpAssetsToFile);
129 AgentTransactions.Add(userID, transactions);
130 }
131
132 return AgentTransactions[userID];
133 }
134 }
135
136 /// <summary>
137 /// Remove the given agent asset transactions. This should be called when a client is departing
138 /// from a scene (and hence won't be making any more transactions here).
139 /// </summary>
140 /// <param name="userID"></param>
141 public void RemoveAgentAssetTransactions(LLUUID userID)
142 {
143 // m_log.DebugFormat("Removing agent asset transactions structure for agent {0}", userID);
144
145 lock (AgentTransactions)
146 {
147 AgentTransactions.Remove(userID);
148 }
149 }
150
151 /// <summary>
152 /// Create an inventory item from data that has been received through a transaction.
153 ///
154 /// This is called when new clothing or body parts are created. It may also be called in other
155 /// situations.
156 /// </summary>
157 /// <param name="remoteClient"></param>
158 /// <param name="transactionID"></param>
159 /// <param name="folderID"></param>
160 /// <param name="callbackID"></param>
161 /// <param name="description"></param>
162 /// <param name="name"></param>
163 /// <param name="invType"></param>
164 /// <param name="type"></param>
165 /// <param name="wearableType"></param>
166 /// <param name="nextOwnerMask"></param>
167 public void HandleItemCreationFromTransaction(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID,
168 uint callbackID, string description, string name, sbyte invType,
169 sbyte type, byte wearableType, uint nextOwnerMask)
170 {
171 m_log.DebugFormat(
172 "[TRANSACTIONS MANAGER] Called HandleItemCreationFromTransaction with item {0}", name);
173
174 AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
175
176 transactions.RequestCreateInventoryItem(
177 remoteClient, transactionID, folderID, callbackID, description,
178 name, invType, type, wearableType, nextOwnerMask);
179 }
180
181 /// <summary>
182 /// Update an inventory item with data that has been received through a transaction.
183 ///
184 /// This is called when clothing or body parts are updated (for instance, with new textures or
185 /// colours). It may also be called in other situations.
186 /// </summary>
187 /// <param name="remoteClient"></param>
188 /// <param name="transactionID"></param>
189 /// <param name="item"></param>
190 public void HandleItemUpdateFromTransaction(IClientAPI remoteClient, LLUUID transactionID,
191 InventoryItemBase item)
192 {
193 m_log.DebugFormat(
194 "[TRANSACTIONS MANAGER] Called HandleItemUpdateFromTransaction with item {0}",
195 item.inventoryName);
196
197 AgentAssetTransactions transactions
198 = GetUserTransactions(remoteClient.AgentId);
199
200 transactions.RequestUpdateInventoryItem(remoteClient, transactionID, item);
201 }
202
203 /// <summary>
204 /// Request that a client (agent) begin an asset transfer.
205 /// </summary>
206 /// <param name="remoteClient"></param>
207 /// <param name="assetID"></param>
208 /// <param name="transaction"></param>
209 /// <param name="type"></param>
210 /// <param name="data"></param></param>
211 /// <param name="tempFile"></param>
212 public void HandleUDPUploadRequest(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type,
213 byte[] data, bool storeLocal, bool tempFile)
214 {
215 // Console.WriteLine("asset upload of " + assetID);
216 AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
217
218 AgentAssetTransactions.AssetXferUploader uploader = transactions.RequestXferUploader(transaction);
219 if (uploader != null)
220 {
221
222 if (uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal, tempFile))
223 {
224
225 }
226 }
227 }
228
229 /// <summary>
230 /// Handle asset transfer data packets received in response to the asset upload request in
231 /// HandleUDPUploadRequest()
232 /// </summary>
233 /// <param name="remoteClient"></param>
234 /// <param name="xferID"></param>
235 /// <param name="packetID"></param>
236 /// <param name="data"></param>
237 public void HandleXfer(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data)
238 {
239 AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
240
241 transactions.HandleXfer(xferID, packetID, data);
242 }
243 }
244}
diff --git a/OpenSim/Region/Environment/Modules/AgentAssetsTransactions.cs b/OpenSim/Region/Environment/Modules/AgentAssetsTransactions.cs
new file mode 100644
index 0000000..d9126f4
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/AgentAssetsTransactions.cs
@@ -0,0 +1,382 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.IO;
5using libsecondlife;
6using libsecondlife.Packets;
7using OpenSim.Framework.Servers;
8using OpenSim.Framework;
9using OpenSim.Framework.Communications.Cache;
10
11namespace OpenSim.Region.Environment.Modules
12{
13
14 /// <summary>
15 /// Manage asset transactions for a single agent.
16 /// </summary>
17 public class AgentAssetTransactions
18 {
19 //private static readonly log4net.ILog m_log
20 // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
21
22 // Fields
23 public LLUUID UserID;
24 public Dictionary<LLUUID, AssetXferUploader> XferUploaders = new Dictionary<LLUUID, AssetXferUploader>();
25 public AgentAssetTransactionsManager Manager;
26 private bool m_dumpAssetsToFile;
27
28 // Methods
29 public AgentAssetTransactions(LLUUID agentID, AgentAssetTransactionsManager manager, bool dumpAssetsToFile)
30 {
31 UserID = agentID;
32 Manager = manager;
33 m_dumpAssetsToFile = dumpAssetsToFile;
34 }
35
36 public AssetXferUploader RequestXferUploader(LLUUID transactionID)
37 {
38 if (!XferUploaders.ContainsKey(transactionID))
39 {
40 AssetXferUploader uploader = new AssetXferUploader(this, m_dumpAssetsToFile);
41
42 lock (XferUploaders)
43 {
44 XferUploaders.Add(transactionID, uploader);
45 }
46
47 return uploader;
48 }
49 return null;
50 }
51
52 public void HandleXfer(ulong xferID, uint packetID, byte[] data)
53 {
54 AssetXferUploader uploaderFound = null;
55
56 lock (XferUploaders)
57 {
58 foreach (AssetXferUploader uploader in XferUploaders.Values)
59 {
60 if (uploader.XferID == xferID)
61 {
62 break;
63 }
64 }
65
66 }
67 }
68
69 public void RequestCreateInventoryItem(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID,
70 uint callbackID, string description, string name, sbyte invType,
71 sbyte type, byte wearableType, uint nextOwnerMask)
72 {
73 if (XferUploaders.ContainsKey(transactionID))
74 {
75 XferUploaders[transactionID].RequestCreateInventoryItem(remoteClient, transactionID, folderID,
76 callbackID, description, name, invType, type,
77 wearableType, nextOwnerMask);
78 }
79 }
80
81 public void RequestUpdateInventoryItem(IClientAPI remoteClient, LLUUID transactionID,
82 InventoryItemBase item)
83 {
84 if (XferUploaders.ContainsKey(transactionID))
85 {
86 XferUploaders[transactionID].RequestUpdateInventoryItem(remoteClient, transactionID, item);
87 }
88 }
89
90 /// <summary>
91 /// Get an uploaded asset. If the data is successfully retrieved, the transaction will be removed.
92 /// </summary>
93 /// <param name="transactionID"></param>
94 /// <returns>The asset if the upload has completed, null if it has not.</returns>
95 public AssetBase GetTransactionAsset(LLUUID transactionID)
96 {
97 if (XferUploaders.ContainsKey(transactionID))
98 {
99 AssetXferUploader uploader = XferUploaders[transactionID];
100 AssetBase asset = uploader.GetAssetData();
101
102 lock (XferUploaders)
103 {
104 XferUploaders.Remove(transactionID);
105 }
106
107 return asset;
108 }
109
110 return null;
111 }
112
113 // Nested Types
114 public class AssetXferUploader
115 {
116 // Fields
117 public bool AddToInventory;
118 public AssetBase Asset;
119 public LLUUID InventFolder = LLUUID.Zero;
120 private IClientAPI ourClient;
121 public LLUUID TransactionID = LLUUID.Zero;
122 public bool UploadComplete;
123 public ulong XferID;
124 private string m_name = String.Empty;
125 private string m_description = String.Empty;
126 private sbyte type = 0;
127 private sbyte invType = 0;
128 private uint nextPerm = 0;
129 private bool m_finished = false;
130 private bool m_createItem = false;
131 private AgentAssetTransactions m_userTransactions;
132 private bool m_storeLocal;
133 private bool m_dumpAssetToFile;
134
135 public AssetXferUploader(AgentAssetTransactions transactions, bool dumpAssetToFile)
136 {
137 m_userTransactions = transactions;
138 m_dumpAssetToFile = dumpAssetToFile;
139 }
140
141 /// <summary>
142 /// Process transfer data received from the client.
143 /// </summary>
144 /// <param name="xferID"></param>
145 /// <param name="packetID"></param>
146 /// <param name="data"></param>
147 /// <returns>True if the transfer is complete, false otherwise or if the xferID was not valid</returns>
148 public bool HandleXferPacket(ulong xferID, uint packetID, byte[] data)
149 {
150 if (XferID == xferID)
151 {
152 if (Asset.Data.Length > 1)
153 {
154 byte[] destinationArray = new byte[Asset.Data.Length + data.Length];
155 Array.Copy(Asset.Data, 0, destinationArray, 0, Asset.Data.Length);
156 Array.Copy(data, 0, destinationArray, Asset.Data.Length, data.Length);
157 Asset.Data = destinationArray;
158 }
159 else
160 {
161 byte[] buffer2 = new byte[data.Length - 4];
162 Array.Copy(data, 4, buffer2, 0, data.Length - 4);
163 Asset.Data = buffer2;
164 }
165 ConfirmXferPacketPacket newPack = new ConfirmXferPacketPacket();
166 newPack.XferID.ID = xferID;
167 newPack.XferID.Packet = packetID;
168 ourClient.OutPacket(newPack, ThrottleOutPacketType.Asset);
169 if ((packetID & 0x80000000) != 0)
170 {
171 SendCompleteMessage();
172 return true;
173 }
174 }
175
176 return false;
177 }
178
179 /// <summary>
180 /// Initialise asset transfer from the client
181 /// </summary>
182 /// <param name="xferID"></param>
183 /// <param name="packetID"></param>
184 /// <param name="data"></param>
185 /// <returns>True if the transfer is complete, false otherwise</returns>
186 public bool Initialise(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data,
187 bool storeLocal, bool tempFile)
188 {
189 ourClient = remoteClient;
190 Asset = new AssetBase();
191 Asset.FullID = assetID;
192 Asset.InvType = type;
193 Asset.Type = type;
194 Asset.Data = data;
195 Asset.Name = "blank";
196 Asset.Description = "empty";
197 Asset.Local = storeLocal;
198 Asset.Temporary = tempFile;
199
200 TransactionID = transaction;
201 m_storeLocal = storeLocal;
202 if (Asset.Data.Length > 2)
203 {
204 SendCompleteMessage();
205 return true;
206 }
207 else
208 {
209 RequestStartXfer();
210 }
211
212 return false;
213 }
214
215 protected void RequestStartXfer()
216 {
217 UploadComplete = false;
218 XferID = Util.GetNextXferID();
219 RequestXferPacket newPack = new RequestXferPacket();
220 newPack.XferID.ID = XferID;
221 newPack.XferID.VFileType = Asset.Type;
222 newPack.XferID.VFileID = Asset.FullID;
223 newPack.XferID.FilePath = 0;
224 newPack.XferID.Filename = new byte[0];
225 ourClient.OutPacket(newPack, ThrottleOutPacketType.Asset);
226 }
227
228 protected void SendCompleteMessage()
229 {
230 UploadComplete = true;
231 AssetUploadCompletePacket newPack = new AssetUploadCompletePacket();
232 newPack.AssetBlock.Type = Asset.Type;
233 newPack.AssetBlock.Success = true;
234 newPack.AssetBlock.UUID = Asset.FullID;
235 ourClient.OutPacket(newPack, ThrottleOutPacketType.Asset);
236 m_finished = true;
237 if (m_createItem)
238 {
239 DoCreateItem();
240 }
241 else if (m_storeLocal)
242 {
243 m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset);
244 }
245
246 // Console.WriteLine("upload complete "+ this.TransactionID);
247
248 if (m_dumpAssetToFile)
249 {
250 DateTime now = DateTime.Now;
251 string filename =
252 String.Format("{6}_{7}_{0:d2}{1:d2}{2:d2}_{3:d2}{4:d2}{5:d2}.dat", now.Year, now.Month, now.Day,
253 now.Hour, now.Minute, now.Second, Asset.Name, Asset.Type);
254 SaveAssetToFile(filename, Asset.Data);
255 }
256 }
257
258 ///Left this in and commented in case there are unforseen issues
259 //private void SaveAssetToFile(string filename, byte[] data)
260 //{
261 // FileStream fs = File.Create(filename);
262 // BinaryWriter bw = new BinaryWriter(fs);
263 // bw.Write(data);
264 // bw.Close();
265 // fs.Close();
266 //}
267 private void SaveAssetToFile(string filename, byte[] data)
268 {
269 string assetPath = "UserAssets";
270 if (!Directory.Exists(assetPath))
271 {
272 Directory.CreateDirectory(assetPath);
273 }
274 FileStream fs = File.Create(Path.Combine(assetPath, filename));
275 BinaryWriter bw = new BinaryWriter(fs);
276 bw.Write(data);
277 bw.Close();
278 fs.Close();
279 }
280
281 public void RequestCreateInventoryItem(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID,
282 uint callbackID, string description, string name, sbyte invType,
283 sbyte type, byte wearableType, uint nextOwnerMask)
284 {
285 if (TransactionID == transactionID)
286 {
287 InventFolder = folderID;
288 m_name = name;
289 m_description = description;
290 this.type = type;
291 this.invType = invType;
292 nextPerm = nextOwnerMask;
293 Asset.Name = name;
294 Asset.Description = description;
295 Asset.Type = type;
296 Asset.InvType = invType;
297 m_createItem = true;
298 if (m_finished)
299 {
300 DoCreateItem();
301 }
302 }
303 }
304
305 public void RequestUpdateInventoryItem(IClientAPI remoteClient, LLUUID transactionID,
306 InventoryItemBase item)
307 {
308 if (TransactionID == transactionID)
309 {
310 CachedUserInfo userInfo =
311 m_userTransactions.Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails(
312 remoteClient.AgentId);
313
314 if (userInfo != null)
315 {
316 LLUUID assetID = LLUUID.Combine(transactionID, remoteClient.SecureSessionId);
317
318 AssetBase asset
319 = m_userTransactions.Manager.MyScene.CommsManager.AssetCache.GetAsset(
320 assetID, (item.assetType == (int) AssetType.Texture ? true : false));
321
322 if (asset == null)
323 {
324 asset = m_userTransactions.GetTransactionAsset(transactionID);
325 }
326
327 if (asset != null && asset.FullID == assetID)
328 {
329 asset.Name = item.inventoryName;
330 asset.Description = item.inventoryDescription;
331 asset.InvType = (sbyte) item.invType;
332 asset.Type = (sbyte) item.assetType;
333 item.assetID = asset.FullID;
334
335 m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset);
336 }
337
338 userInfo.UpdateItem(remoteClient.AgentId, item);
339 }
340 }
341 }
342
343 private void DoCreateItem()
344 {
345 //really need to fix this call, if lbsa71 saw this he would die.
346 m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset);
347 CachedUserInfo userInfo =
348 m_userTransactions.Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails(ourClient.AgentId);
349 if (userInfo != null)
350 {
351 InventoryItemBase item = new InventoryItemBase();
352 item.avatarID = ourClient.AgentId;
353 item.creatorsID = ourClient.AgentId;
354 item.inventoryID = LLUUID.Random();
355 item.assetID = Asset.FullID;
356 item.inventoryDescription = m_description;
357 item.inventoryName = m_name;
358 item.assetType = type;
359 item.invType = invType;
360 item.parentFolderID = InventFolder;
361 item.inventoryBasePermissions = 2147483647;
362 item.inventoryCurrentPermissions = 2147483647;
363 item.inventoryNextPermissions = nextPerm;
364
365 userInfo.AddItem(ourClient.AgentId, item);
366 ourClient.SendInventoryItemCreateUpdate(item);
367 }
368 }
369
370 public AssetBase GetAssetData()
371 {
372 if (m_finished)
373 {
374 return Asset;
375 }
376 return null;
377 }
378 }
379
380 }
381
382}