opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 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 OpenSimulator 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 | |||
28 | using System; |
||
29 | using System.Collections.Generic; |
||
30 | using System.Reflection; |
||
31 | using log4net; |
||
32 | using Mono.Addins; |
||
33 | using Nini.Config; |
||
34 | using OpenMetaverse; |
||
35 | using OpenSim.Framework; |
||
36 | using OpenSim.Region.Framework.Interfaces; |
||
37 | using OpenSim.Region.Framework.Scenes; |
||
38 | using OpenSim.Services.Interfaces; |
||
39 | |||
40 | namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer |
||
41 | { |
||
42 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "InventoryTransferModule")] |
||
43 | public class InventoryTransferModule : ISharedRegionModule |
||
44 | { |
||
45 | private static readonly ILog m_log |
||
46 | = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
47 | |||
48 | /// <summary> |
||
49 | private List<Scene> m_Scenelist = new List<Scene>(); |
||
50 | |||
51 | private IMessageTransferModule m_TransferModule; |
||
52 | private bool m_Enabled = true; |
||
53 | |||
54 | #region Region Module interface |
||
55 | |||
56 | public void Initialise(IConfigSource config) |
||
57 | { |
||
58 | if (config.Configs["Messaging"] != null) |
||
59 | { |
||
60 | // Allow disabling this module in config |
||
61 | // |
||
62 | if (config.Configs["Messaging"].GetString( |
||
63 | "InventoryTransferModule", "InventoryTransferModule") != |
||
64 | "InventoryTransferModule") |
||
65 | { |
||
66 | m_Enabled = false; |
||
67 | return; |
||
68 | } |
||
69 | } |
||
70 | } |
||
71 | |||
72 | public void AddRegion(Scene scene) |
||
73 | { |
||
74 | if (!m_Enabled) |
||
75 | return; |
||
76 | |||
77 | m_Scenelist.Add(scene); |
||
78 | |||
79 | // scene.RegisterModuleInterface<IInventoryTransferModule>(this); |
||
80 | |||
81 | scene.EventManager.OnNewClient += OnNewClient; |
||
82 | scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage; |
||
83 | } |
||
84 | |||
85 | public void RegionLoaded(Scene scene) |
||
86 | { |
||
87 | if (m_TransferModule == null) |
||
88 | { |
||
89 | m_TransferModule = m_Scenelist[0].RequestModuleInterface<IMessageTransferModule>(); |
||
90 | if (m_TransferModule == null) |
||
91 | { |
||
92 | m_log.Error("[INVENTORY TRANSFER]: No Message transfer module found, transfers will be local only"); |
||
93 | m_Enabled = false; |
||
94 | |||
95 | // m_Scenelist.Clear(); |
||
96 | // scene.EventManager.OnNewClient -= OnNewClient; |
||
97 | scene.EventManager.OnIncomingInstantMessage -= OnGridInstantMessage; |
||
98 | } |
||
99 | } |
||
100 | } |
||
101 | |||
102 | public void RemoveRegion(Scene scene) |
||
103 | { |
||
104 | scene.EventManager.OnNewClient -= OnNewClient; |
||
105 | scene.EventManager.OnIncomingInstantMessage -= OnGridInstantMessage; |
||
106 | m_Scenelist.Remove(scene); |
||
107 | } |
||
108 | |||
109 | public void PostInitialise() |
||
110 | { |
||
111 | } |
||
112 | |||
113 | public void Close() |
||
114 | { |
||
115 | } |
||
116 | |||
117 | public string Name |
||
118 | { |
||
119 | get { return "InventoryModule"; } |
||
120 | } |
||
121 | |||
122 | public Type ReplaceableInterface |
||
123 | { |
||
124 | get { return null; } |
||
125 | } |
||
126 | |||
127 | #endregion |
||
128 | |||
129 | private void OnNewClient(IClientAPI client) |
||
130 | { |
||
131 | // Inventory giving is conducted via instant message |
||
132 | client.OnInstantMessage += OnInstantMessage; |
||
133 | } |
||
134 | |||
135 | private Scene FindClientScene(UUID agentId) |
||
136 | { |
||
137 | lock (m_Scenelist) |
||
138 | { |
||
139 | foreach (Scene scene in m_Scenelist) |
||
140 | { |
||
141 | ScenePresence presence = scene.GetScenePresence(agentId); |
||
142 | if (presence != null) |
||
143 | return scene; |
||
144 | } |
||
145 | } |
||
146 | return null; |
||
147 | } |
||
148 | |||
149 | private void OnInstantMessage(IClientAPI client, GridInstantMessage im) |
||
150 | { |
||
151 | // m_log.DebugFormat( |
||
152 | // "[INVENTORY TRANSFER]: {0} IM type received from client {1}. From={2} ({3}), To={4}", |
||
153 | // (InstantMessageDialog)im.dialog, client.Name, |
||
154 | // im.fromAgentID, im.fromAgentName, im.toAgentID); |
||
155 | |||
156 | Scene scene = FindClientScene(client.AgentId); |
||
157 | |||
158 | if (scene == null) // Something seriously wrong here. |
||
159 | return; |
||
160 | |||
161 | if (im.dialog == (byte) InstantMessageDialog.InventoryOffered) |
||
162 | { |
||
163 | //m_log.DebugFormat("Asset type {0}", ((AssetType)im.binaryBucket[0])); |
||
164 | |||
165 | if (im.binaryBucket.Length < 17) // Invalid |
||
166 | return; |
||
167 | |||
168 | UUID receipientID = new UUID(im.toAgentID); |
||
169 | ScenePresence user = scene.GetScenePresence(receipientID); |
||
170 | UUID copyID; |
||
171 | |||
172 | // First byte is the asset type |
||
173 | AssetType assetType = (AssetType)im.binaryBucket[0]; |
||
174 | |||
175 | if (AssetType.Folder == assetType) |
||
176 | { |
||
177 | UUID folderID = new UUID(im.binaryBucket, 1); |
||
178 | |||
179 | m_log.DebugFormat( |
||
180 | "[INVENTORY TRANSFER]: Inserting original folder {0} into agent {1}'s inventory", |
||
181 | folderID, new UUID(im.toAgentID)); |
||
182 | |||
183 | InventoryFolderBase folderCopy |
||
184 | = scene.GiveInventoryFolder(receipientID, client.AgentId, folderID, UUID.Zero); |
||
185 | |||
186 | if (folderCopy == null) |
||
187 | { |
||
188 | client.SendAgentAlertMessage("Can't find folder to give. Nothing given.", false); |
||
189 | return; |
||
190 | } |
||
191 | |||
192 | // The outgoing binary bucket should contain only the byte which signals an asset folder is |
||
193 | // being copied and the following bytes for the copied folder's UUID |
||
194 | copyID = folderCopy.ID; |
||
195 | byte[] copyIDBytes = copyID.GetBytes(); |
||
196 | im.binaryBucket = new byte[1 + copyIDBytes.Length]; |
||
197 | im.binaryBucket[0] = (byte)AssetType.Folder; |
||
198 | Array.Copy(copyIDBytes, 0, im.binaryBucket, 1, copyIDBytes.Length); |
||
199 | |||
200 | if (user != null) |
||
201 | user.ControllingClient.SendBulkUpdateInventory(folderCopy); |
||
202 | |||
203 | // HACK!! |
||
204 | // Insert the ID of the copied folder into the IM so that we know which item to move to trash if it |
||
205 | // is rejected. |
||
206 | // XXX: This is probably a misuse of the session ID slot. |
||
207 | im.imSessionID = copyID.Guid; |
||
208 | } |
||
209 | else |
||
210 | { |
||
211 | // First byte of the array is probably the item type |
||
212 | // Next 16 bytes are the UUID |
||
213 | |||
214 | UUID itemID = new UUID(im.binaryBucket, 1); |
||
215 | |||
216 | m_log.DebugFormat("[INVENTORY TRANSFER]: (giving) Inserting item {0} "+ |
||
217 | "into agent {1}'s inventory", |
||
218 | itemID, new UUID(im.toAgentID)); |
||
219 | |||
220 | InventoryItemBase itemCopy = scene.GiveInventoryItem( |
||
221 | new UUID(im.toAgentID), |
||
222 | client.AgentId, itemID); |
||
223 | |||
224 | if (itemCopy == null) |
||
225 | { |
||
226 | client.SendAgentAlertMessage("Can't find item to give. Nothing given.", false); |
||
227 | return; |
||
228 | } |
||
229 | |||
230 | copyID = itemCopy.ID; |
||
231 | Array.Copy(copyID.GetBytes(), 0, im.binaryBucket, 1, 16); |
||
232 | |||
233 | if (user != null) |
||
234 | user.ControllingClient.SendBulkUpdateInventory(itemCopy); |
||
235 | |||
236 | // HACK!! |
||
237 | // Insert the ID of the copied item into the IM so that we know which item to move to trash if it |
||
238 | // is rejected. |
||
239 | // XXX: This is probably a misuse of the session ID slot. |
||
240 | im.imSessionID = copyID.Guid; |
||
241 | } |
||
242 | |||
243 | // Send the IM to the recipient. The item is already |
||
244 | // in their inventory, so it will not be lost if |
||
245 | // they are offline. |
||
246 | // |
||
247 | if (user != null) |
||
248 | { |
||
249 | user.ControllingClient.SendInstantMessage(im); |
||
250 | return; |
||
251 | } |
||
252 | else |
||
253 | { |
||
254 | if (m_TransferModule != null) |
||
255 | m_TransferModule.SendInstantMessage(im, delegate(bool success) |
||
256 | { |
||
257 | if (!success) |
||
258 | client.SendAlertMessage("User not online. Inventory has been saved"); |
||
259 | }); |
||
260 | } |
||
261 | } |
||
262 | else if (im.dialog == (byte) InstantMessageDialog.InventoryAccepted) |
||
263 | { |
||
264 | ScenePresence user = scene.GetScenePresence(new UUID(im.toAgentID)); |
||
265 | |||
266 | if (user != null) // Local |
||
267 | { |
||
268 | user.ControllingClient.SendInstantMessage(im); |
||
269 | } |
||
270 | else |
||
271 | { |
||
272 | if (m_TransferModule != null) |
||
273 | m_TransferModule.SendInstantMessage(im, delegate(bool success) { |
||
274 | |||
275 | // justincc - FIXME: Comment out for now. This code was added in commit db91044 Mon Aug 22 2011 |
||
276 | // and is apparently supposed to fix bulk inventory updates after accepting items. But |
||
277 | // instead it appears to cause two copies of an accepted folder for the receiving user in |
||
278 | // at least some cases. Folder/item update is already done when the offer is made (see code above) |
||
279 | |||
280 | // // Send BulkUpdateInventory |
||
281 | // IInventoryService invService = scene.InventoryService; |
||
282 | // UUID inventoryEntityID = new UUID(im.imSessionID); // The inventory item /folder, back from it's trip |
||
283 | // |
||
284 | // InventoryFolderBase folder = new InventoryFolderBase(inventoryEntityID, client.AgentId); |
||
285 | // folder = invService.GetFolder(folder); |
||
286 | // |
||
287 | // ScenePresence fromUser = scene.GetScenePresence(new UUID(im.fromAgentID)); |
||
288 | // |
||
289 | // // If the user has left the scene by the time the message comes back then we can't send |
||
290 | // // them the update. |
||
291 | // if (fromUser != null) |
||
292 | // fromUser.ControllingClient.SendBulkUpdateInventory(folder); |
||
293 | }); |
||
294 | } |
||
295 | } |
||
296 | |||
297 | // XXX: This code was placed here to try and accomodate RLV which moves given folders named #RLV/~<name> |
||
298 | // to the requested folder, which in this case is #RLV. However, it is the viewer that appears to be |
||
299 | // response from renaming the #RLV/~example folder to ~example. For some reason this is not yet |
||
300 | // happening, possibly because we are not sending the correct inventory update messages with the correct |
||
301 | // transaction IDs |
||
302 | else if (im.dialog == (byte) InstantMessageDialog.TaskInventoryAccepted) |
||
303 | { |
||
304 | UUID destinationFolderID = UUID.Zero; |
||
305 | |||
306 | if (im.binaryBucket != null && im.binaryBucket.Length >= 16) |
||
307 | { |
||
308 | destinationFolderID = new UUID(im.binaryBucket, 0); |
||
309 | } |
||
310 | |||
311 | if (destinationFolderID != UUID.Zero) |
||
312 | { |
||
313 | InventoryFolderBase destinationFolder = new InventoryFolderBase(destinationFolderID, client.AgentId); |
||
314 | if (destinationFolder == null) |
||
315 | { |
||
316 | m_log.WarnFormat( |
||
317 | "[INVENTORY TRANSFER]: TaskInventoryAccepted message from {0} in {1} specified folder {2} which does not exist", |
||
318 | client.Name, scene.Name, destinationFolderID); |
||
319 | |||
320 | return; |
||
321 | } |
||
322 | |||
323 | IInventoryService invService = scene.InventoryService; |
||
324 | |||
325 | UUID inventoryID = new UUID(im.imSessionID); // The inventory item/folder, back from it's trip |
||
326 | |||
327 | InventoryItemBase item = new InventoryItemBase(inventoryID, client.AgentId); |
||
328 | item = invService.GetItem(item); |
||
329 | InventoryFolderBase folder = null; |
||
330 | UUID? previousParentFolderID = null; |
||
331 | |||
332 | if (item != null) // It's an item |
||
333 | { |
||
334 | previousParentFolderID = item.Folder; |
||
335 | item.Folder = destinationFolderID; |
||
336 | |||
337 | invService.DeleteItems(item.Owner, new List<UUID>() { item.ID }); |
||
338 | scene.AddInventoryItem(client, item); |
||
339 | } |
||
340 | else |
||
341 | { |
||
342 | folder = new InventoryFolderBase(inventoryID, client.AgentId); |
||
343 | folder = invService.GetFolder(folder); |
||
344 | |||
345 | if (folder != null) // It's a folder |
||
346 | { |
||
347 | previousParentFolderID = folder.ParentID; |
||
348 | folder.ParentID = destinationFolderID; |
||
349 | invService.MoveFolder(folder); |
||
350 | } |
||
351 | } |
||
352 | |||
353 | // Tell client about updates to original parent and new parent (this should probably be factored with existing move item/folder code). |
||
354 | if (previousParentFolderID != null) |
||
355 | { |
||
356 | InventoryFolderBase previousParentFolder |
||
357 | = new InventoryFolderBase((UUID)previousParentFolderID, client.AgentId); |
||
358 | previousParentFolder = invService.GetFolder(previousParentFolder); |
||
359 | scene.SendInventoryUpdate(client, previousParentFolder, true, true); |
||
360 | |||
361 | scene.SendInventoryUpdate(client, destinationFolder, true, true); |
||
362 | } |
||
363 | } |
||
364 | } |
||
365 | else if ( |
||
366 | im.dialog == (byte)InstantMessageDialog.InventoryDeclined |
||
367 | || im.dialog == (byte)InstantMessageDialog.TaskInventoryDeclined) |
||
368 | { |
||
369 | // Here, the recipient is local and we can assume that the |
||
370 | // inventory is loaded. Courtesy of the above bulk update, |
||
371 | // It will have been pushed to the client, too |
||
372 | // |
||
373 | IInventoryService invService = scene.InventoryService; |
||
374 | |||
375 | InventoryFolderBase trashFolder = |
||
376 | invService.GetFolderForType(client.AgentId, AssetType.TrashFolder); |
||
377 | |||
378 | UUID inventoryID = new UUID(im.imSessionID); // The inventory item/folder, back from it's trip |
||
379 | |||
380 | InventoryItemBase item = new InventoryItemBase(inventoryID, client.AgentId); |
||
381 | item = invService.GetItem(item); |
||
382 | InventoryFolderBase folder = null; |
||
383 | UUID? previousParentFolderID = null; |
||
384 | |||
385 | if (item != null && trashFolder != null) |
||
386 | { |
||
387 | previousParentFolderID = item.Folder; |
||
388 | item.Folder = trashFolder.ID; |
||
389 | |||
390 | // Diva comment: can't we just update this item??? |
||
391 | List<UUID> uuids = new List<UUID>(); |
||
392 | uuids.Add(item.ID); |
||
393 | invService.DeleteItems(item.Owner, uuids); |
||
394 | scene.AddInventoryItem(client, item); |
||
395 | } |
||
396 | else |
||
397 | { |
||
398 | folder = new InventoryFolderBase(inventoryID, client.AgentId); |
||
399 | folder = invService.GetFolder(folder); |
||
400 | |||
401 | if (folder != null & trashFolder != null) |
||
402 | { |
||
403 | previousParentFolderID = folder.ParentID; |
||
404 | folder.ParentID = trashFolder.ID; |
||
405 | invService.MoveFolder(folder); |
||
406 | } |
||
407 | } |
||
408 | |||
409 | if ((null == item && null == folder) | null == trashFolder) |
||
410 | { |
||
411 | string reason = String.Empty; |
||
412 | |||
413 | if (trashFolder == null) |
||
414 | reason += " Trash folder not found."; |
||
415 | if (item == null) |
||
416 | reason += " Item not found."; |
||
417 | if (folder == null) |
||
418 | reason += " Folder not found."; |
||
419 | |||
420 | client.SendAgentAlertMessage("Unable to delete "+ |
||
421 | "received inventory" + reason, false); |
||
422 | } |
||
423 | // Tell client about updates to original parent and new parent (this should probably be factored with existing move item/folder code). |
||
424 | else if (previousParentFolderID != null) |
||
425 | { |
||
426 | InventoryFolderBase previousParentFolder |
||
427 | = new InventoryFolderBase((UUID)previousParentFolderID, client.AgentId); |
||
428 | previousParentFolder = invService.GetFolder(previousParentFolder); |
||
429 | scene.SendInventoryUpdate(client, previousParentFolder, true, true); |
||
430 | |||
431 | scene.SendInventoryUpdate(client, trashFolder, true, true); |
||
432 | } |
||
433 | |||
434 | if (im.dialog == (byte)InstantMessageDialog.InventoryDeclined) |
||
435 | { |
||
436 | ScenePresence user = scene.GetScenePresence(new UUID(im.toAgentID)); |
||
437 | |||
438 | if (user != null) // Local |
||
439 | { |
||
440 | user.ControllingClient.SendInstantMessage(im); |
||
441 | } |
||
442 | else |
||
443 | { |
||
444 | if (m_TransferModule != null) |
||
445 | m_TransferModule.SendInstantMessage(im, delegate(bool success) { }); |
||
446 | } |
||
447 | } |
||
448 | } |
||
449 | } |
||
450 | |||
451 | /// <summary> |
||
452 | /// |
||
453 | /// </summary> |
||
454 | /// <param name="im"></param> |
||
455 | private void OnGridInstantMessage(GridInstantMessage im) |
||
456 | { |
||
457 | // Check if it's a type of message that we should handle |
||
458 | if (!((im.dialog == (byte) InstantMessageDialog.InventoryOffered) |
||
459 | || (im.dialog == (byte) InstantMessageDialog.InventoryAccepted) |
||
460 | || (im.dialog == (byte) InstantMessageDialog.InventoryDeclined) |
||
461 | || (im.dialog == (byte) InstantMessageDialog.TaskInventoryDeclined))) |
||
462 | return; |
||
463 | |||
464 | m_log.DebugFormat( |
||
465 | "[INVENTORY TRANSFER]: {0} IM type received from grid. From={1} ({2}), To={3}", |
||
466 | (InstantMessageDialog)im.dialog, im.fromAgentID, im.fromAgentName, im.toAgentID); |
||
467 | |||
468 | // Check if this is ours to handle |
||
469 | // |
||
470 | Scene scene = FindClientScene(new UUID(im.toAgentID)); |
||
471 | |||
472 | if (scene == null) |
||
473 | return; |
||
474 | |||
475 | // Find agent to deliver to |
||
476 | // |
||
477 | ScenePresence user = scene.GetScenePresence(new UUID(im.toAgentID)); |
||
478 | |||
479 | if (user != null) |
||
480 | { |
||
481 | user.ControllingClient.SendInstantMessage(im); |
||
482 | |||
483 | if (im.dialog == (byte)InstantMessageDialog.InventoryOffered) |
||
484 | { |
||
485 | AssetType assetType = (AssetType)im.binaryBucket[0]; |
||
486 | UUID inventoryID = new UUID(im.binaryBucket, 1); |
||
487 | |||
488 | IInventoryService invService = scene.InventoryService; |
||
489 | InventoryNodeBase node = null; |
||
490 | if (AssetType.Folder == assetType) |
||
491 | { |
||
492 | InventoryFolderBase folder = new InventoryFolderBase(inventoryID, new UUID(im.toAgentID)); |
||
493 | node = invService.GetFolder(folder); |
||
494 | } |
||
495 | else |
||
496 | { |
||
497 | InventoryItemBase item = new InventoryItemBase(inventoryID, new UUID(im.toAgentID)); |
||
498 | node = invService.GetItem(item); |
||
499 | } |
||
500 | |||
501 | if (node != null) |
||
502 | user.ControllingClient.SendBulkUpdateInventory(node); |
||
503 | } |
||
504 | } |
||
505 | } |
||
506 | } |
||
507 | } |