29 using System.Collections.Generic;
30 using System.Reflection;
35 using OpenSim.Framework;
36 using OpenSim.Region.Framework.Interfaces;
37 using OpenSim.Region.Framework.Scenes;
38 using OpenSim.Services.Interfaces;
42 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"InventoryTransferModule")]
45 private static readonly ILog m_log
46 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49 private List<Scene> m_Scenelist =
new List<Scene>();
52 private bool m_Enabled =
true;
54 #region Region Module interface
58 if (config.Configs[
"Messaging"] != null)
62 if (config.Configs[
"Messaging"].GetString(
63 "InventoryTransferModule",
"InventoryTransferModule") !=
64 "InventoryTransferModule")
77 m_Scenelist.Add(scene);
81 scene.EventManager.OnNewClient += OnNewClient;
82 scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage;
87 if (m_TransferModule == null)
90 if (m_TransferModule == null)
92 m_log.Error(
"[INVENTORY TRANSFER]: No Message transfer module found, transfers will be local only");
97 scene.EventManager.OnIncomingInstantMessage -= OnGridInstantMessage;
104 scene.EventManager.OnNewClient -= OnNewClient;
105 scene.EventManager.OnIncomingInstantMessage -= OnGridInstantMessage;
106 m_Scenelist.Remove(scene);
119 get {
return "InventoryModule"; }
122 public Type ReplaceableInterface
132 client.OnInstantMessage += OnInstantMessage;
135 private Scene FindClientScene(UUID agentId)
139 foreach (
Scene scene
in m_Scenelist)
142 if (presence != null)
161 if (im.
dialog == (byte) InstantMessageDialog.InventoryOffered)
175 if (AssetType.Folder == assetType)
180 "[INVENTORY TRANSFER]: Inserting original folder {0} into agent {1}'s inventory",
184 = scene.GiveInventoryFolder(client, recipientID, client.AgentId, folderID, UUID.Zero);
186 if (folderCopy == null)
188 client.SendAgentAlertMessage(
"Can't find folder to give. Nothing given.",
false);
194 copyID = folderCopy.ID;
195 byte[] copyIDBytes = copyID.GetBytes();
196 im.binaryBucket =
new byte[1 + copyIDBytes.Length];
197 im.binaryBucket[0] = (byte)AssetType.Folder;
201 user.ControllingClient.SendBulkUpdateInventory(folderCopy);
207 im.imSessionID = copyID.Guid;
216 m_log.DebugFormat(
"[INVENTORY TRANSFER]: (giving) Inserting item {0} "+
217 "into agent {1}'s inventory",
223 if (itemCopy == null)
225 client.SendAgentAlertMessage(message,
false);
229 copyID = itemCopy.ID;
230 Array.Copy(copyID.GetBytes(), 0, im.
binaryBucket, 1, 16);
233 user.ControllingClient.SendBulkUpdateInventory(itemCopy);
239 im.imSessionID = copyID.Guid;
250 user.ControllingClient.SendInstantMessage(im);
255 if (m_TransferModule != null)
256 m_TransferModule.SendInstantMessage(im, delegate(
bool success)
259 client.SendAlertMessage(
"User not online. Inventory has been saved");
263 else if (im.
dialog == (byte) InstantMessageDialog.InventoryAccepted ||
264 im.dialog == (byte) InstantMessageDialog.TaskInventoryAccepted)
271 if (im.
dialog == (byte) InstantMessageDialog.TaskInventoryAccepted)
274 folder = invService.GetFolder(folder);
281 if (destFolderID !=
UUID.Zero)
284 destFolder = invService.GetFolder(destFolder);
285 if (destFolder != null)
289 folder.ParentID = destFolder.ID;
290 invService.MoveFolder(folder);
291 client.SendBulkUpdateInventory(folder);
303 user.ControllingClient.SendInstantMessage(im);
307 if (m_TransferModule != null)
308 m_TransferModule.SendInstantMessage(im, delegate(
bool success) {});
317 else if (im.
dialog == (byte) InstantMessageDialog.TaskInventoryAccepted)
319 UUID destinationFolderID = UUID.Zero;
326 if (destinationFolderID !=
UUID.Zero)
329 if (destinationFolder == null)
332 "[INVENTORY TRANSFER]: TaskInventoryAccepted message from {0} in {1} specified folder {2} which does not exist",
333 client.Name, scene.Name, destinationFolderID);
343 item = invService.GetItem(item);
345 UUID? previousParentFolderID = null;
349 previousParentFolderID = item.Folder;
350 item.Folder = destinationFolderID;
352 invService.DeleteItems(item.Owner,
new List<UUID>() { item.ID });
353 scene.AddInventoryItem(client, item);
358 folder = invService.GetFolder(folder);
362 previousParentFolderID = folder.ParentID;
363 folder.ParentID = destinationFolderID;
364 invService.MoveFolder(folder);
369 if (previousParentFolderID != null)
373 previousParentFolder = invService.GetFolder(previousParentFolder);
374 scene.SendInventoryUpdate(client, previousParentFolder,
true,
true);
376 scene.SendInventoryUpdate(client, destinationFolder,
true,
true);
381 im.
dialog == (byte)InstantMessageDialog.InventoryDeclined
382 || im.dialog == (byte)InstantMessageDialog.TaskInventoryDeclined)
391 invService.GetFolderForType(client.AgentId, FolderType.Trash);
396 item = invService.GetItem(item);
398 UUID? previousParentFolderID = null;
400 if (item != null && trashFolder != null)
402 previousParentFolderID = item.Folder;
403 item.Folder = trashFolder.ID;
406 List<UUID> uuids =
new List<UUID>();
408 invService.DeleteItems(item.Owner, uuids);
409 scene.AddInventoryItem(client, item);
414 folder = invService.GetFolder(folder);
416 if (folder != null & trashFolder != null)
418 previousParentFolderID = folder.ParentID;
419 folder.ParentID = trashFolder.ID;
420 invService.MoveFolder(folder);
421 client.SendBulkUpdateInventory(folder);
425 if ((null == item && null == folder) | null == trashFolder)
427 string reason = String.Empty;
429 if (trashFolder == null)
430 reason +=
" Trash folder not found.";
432 reason +=
" Item not found.";
434 reason +=
" Folder not found.";
436 client.SendAgentAlertMessage(
"Unable to delete "+
437 "received inventory" + reason,
false);
440 else if (previousParentFolderID != null)
444 previousParentFolder = invService.GetFolder(previousParentFolder);
445 scene.SendInventoryUpdate(client, previousParentFolder,
true,
true);
447 scene.SendInventoryUpdate(client, trashFolder,
true,
true);
450 if (im.
dialog == (byte)InstantMessageDialog.InventoryDeclined)
456 user.ControllingClient.SendInstantMessage(im);
460 if (m_TransferModule != null)
461 m_TransferModule.SendInstantMessage(im, delegate(
bool success) { });
489 if (im.
dialog == (byte) InstantMessageDialog.InventoryOffered)
499 if (AssetType.Folder == assetType)
506 scene.InventoryService.GetFolder(given);
509 user.ControllingClient.SendBulkUpdateInventory(folder);
518 scene.InventoryService.GetItem(given);
522 user.ControllingClient.SendBulkUpdateInventory(item);
525 user.ControllingClient.SendInstantMessage(im);
527 if (im.
dialog == (byte) InstantMessageDialog.TaskInventoryOffered)
537 if (AssetType.Folder == assetType)
544 scene.InventoryService.GetFolder(given);
547 user.ControllingClient.SendBulkUpdateInventory(folder);
556 scene.InventoryService.GetItem(given);
560 user.ControllingClient.SendBulkUpdateInventory(item);
565 Byte[] bucket =
new Byte[1];
566 bucket[0] = im.binaryBucket[0];
567 im.binaryBucket = bucket;
569 user.ControllingClient.SendInstantMessage(im);
571 else if (im.
dialog == (byte) InstantMessageDialog.InventoryAccepted ||
572 im.dialog == (byte) InstantMessageDialog.InventoryDeclined ||
573 im.
dialog == (byte) InstantMessageDialog.TaskInventoryDeclined ||
574 im.dialog == (byte) InstantMessageDialog.TaskInventoryAccepted)
576 user.ControllingClient.SendInstantMessage(im);
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
Inventory Item - contains all the properties associated with an individual inventory piece...
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
Interactive OpenSim region server
UUID ID
A UUID containing the ID for the inventory node itself
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
void Initialise(IConfigSource config)
This is called to initialize the region module. For shared modules, this is called exactly once...