several changes to (task)inventory offering

master
UbitUmarov 2020-02-14 19:47:57 +00:00
parent 55333a5171
commit 59414467e2
1 changed files with 129 additions and 162 deletions

View File

@ -154,34 +154,42 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
// im.fromAgentID, im.fromAgentName, im.toAgentID); // im.fromAgentID, im.fromAgentName, im.toAgentID);
Scene scene = FindClientScene(client.AgentId); Scene scene = FindClientScene(client.AgentId);
if (scene == null) // Something seriously wrong here. if (scene == null) // Something seriously wrong here.
return; return;
UUID agentID = client.AgentId;
if (im.dialog == (byte) InstantMessageDialog.InventoryOffered) if (im.dialog == (byte) InstantMessageDialog.InventoryOffered)
{ {
//m_log.DebugFormat("Asset type {0}", ((AssetType)im.binaryBucket[0]));
if (im.binaryBucket.Length < 17) // Invalid if (im.binaryBucket.Length < 17) // Invalid
return; return;
UUID recipientID = new UUID(im.toAgentID); UUID recipientID = new UUID(im.toAgentID);
ScenePresence user = scene.GetScenePresence(recipientID); ScenePresence recipientAgent = scene.GetScenePresence(recipientID);
UUID copyID; UUID copyID;
// First byte is the asset type // First byte is the asset type
AssetType assetType = (AssetType)im.binaryBucket[0]; AssetType assetType = (AssetType)im.binaryBucket[0];
if(assetType == AssetType.LinkFolder || assetType == AssetType.Link)
{
client.SendAgentAlertMessage("Can't give a link. Nothing given.", false);
return;
}
if (AssetType.Folder == assetType) if (assetType == AssetType.Folder)
{ {
UUID folderID = new UUID(im.binaryBucket, 1); UUID folderID = new UUID(im.binaryBucket, 1);
if (folderID == UUID.Zero)
{
client.SendAgentAlertMessage("Can't find folder to give. Nothing given.", false);
return;
}
m_log.DebugFormat( m_log.DebugFormat(
"[INVENTORY TRANSFER]: Inserting original folder {0} into agent {1}'s inventory", "[INVENTORY TRANSFER]: offering folder {0} to agent {1}'s inventory",
folderID, new UUID(im.toAgentID)); folderID, recipientID);
InventoryFolderBase folderCopy InventoryFolderBase folderCopy = scene.GiveInventoryFolder(client, recipientID, agentID, folderID, UUID.Zero);
= scene.GiveInventoryFolder(client, recipientID, client.AgentId, folderID, UUID.Zero);
if (folderCopy == null) if (folderCopy == null)
{ {
@ -189,36 +197,30 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
return; return;
} }
// The outgoing binary bucket should contain only the byte which signals an asset folder is
// being copied and the following bytes for the copied folder's UUID
copyID = folderCopy.ID; copyID = folderCopy.ID;
byte[] copyIDBytes = copyID.GetBytes(); copyID.ToBytes(im.binaryBucket,1);
im.binaryBucket = new byte[1 + copyIDBytes.Length];
im.binaryBucket[0] = (byte)AssetType.Folder;
Array.Copy(copyIDBytes, 0, im.binaryBucket, 1, copyIDBytes.Length);
if (user != null)
user.ControllingClient.SendBulkUpdateInventory(folderCopy);
// HACK!!
// Insert the ID of the copied folder into the IM so that we know which item to move to trash if it
// is rejected.
// XXX: This is probably a misuse of the session ID slot.
im.imSessionID = copyID.Guid; im.imSessionID = copyID.Guid;
if (recipientAgent != null)
{
recipientAgent.ControllingClient.SendBulkUpdateInventory(folderCopy);
}
} }
else else
{ {
// First byte of the array is probably the item type
// Next 16 bytes are the UUID
UUID itemID = new UUID(im.binaryBucket, 1); UUID itemID = new UUID(im.binaryBucket, 1);
if (itemID == UUID.Zero)
{
client.SendAgentAlertMessage("Can't find item to give. Nothing given.", false);
return;
}
m_log.DebugFormat("[INVENTORY TRANSFER]: (giving) Inserting item {0} "+ m_log.DebugFormat("[INVENTORY TRANSFER]: (giving) Inserting item {0} "+
"into agent {1}'s inventory", "into agent {1}'s inventory",
itemID, new UUID(im.toAgentID)); itemID, recipientID);
string message; string message;
InventoryItemBase itemCopy = scene.GiveInventoryItem(new UUID(im.toAgentID), client.AgentId, itemID, out message); InventoryItemBase itemCopy = scene.GiveInventoryItem(recipientID, agentID, itemID, out message);
if (itemCopy == null) if (itemCopy == null)
{ {
@ -227,74 +229,46 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
} }
copyID = itemCopy.ID; copyID = itemCopy.ID;
Array.Copy(copyID.GetBytes(), 0, im.binaryBucket, 1, 16); copyID.ToBytes(im.binaryBucket, 1);
if (user != null) if (recipientAgent != null)
user.ControllingClient.SendBulkUpdateInventory(itemCopy); recipientAgent.ControllingClient.SendBulkUpdateInventory(itemCopy);
// HACK!!
// Insert the ID of the copied item into the IM so that we know which item to move to trash if it
// is rejected.
// XXX: This is probably a misuse of the session ID slot.
im.imSessionID = copyID.Guid; im.imSessionID = copyID.Guid;
} }
im.offline = 0;
// Send the IM to the recipient. The item is already // Send the IM to the recipient. The item is already
// in their inventory, so it will not be lost if // in their inventory, so it will not be lost if
// they are offline. // they are offline.
//
if (user != null) if (recipientAgent != null)
{ {
user.ControllingClient.SendInstantMessage(im); im.offline = 0;
recipientAgent.ControllingClient.SendInstantMessage(im);
return; return;
} }
else else
{ {
im.offline = 0;
if (m_TransferModule != null) if (m_TransferModule != null)
{
m_TransferModule.SendInstantMessage(im, delegate(bool success) m_TransferModule.SendInstantMessage(im, delegate(bool success)
{ {
if (!success) if (!success)
client.SendAlertMessage("User not online. Inventory has been saved"); client.SendAlertMessage("User not online. Inventory has been saved");
}); });
}
} }
} }
else if (im.dialog == (byte) InstantMessageDialog.InventoryAccepted) else if (im.dialog == (byte) InstantMessageDialog.InventoryAccepted)
{ {
UUID inventoryID = new UUID(im.imSessionID); // The inventory item/folder, back from it's trip UUID inventoryID = new UUID(im.imSessionID); // The inventory item/folder, back from it's trip
if(inventoryID == UUID.Zero)
return;
IInventoryService invService = scene.InventoryService; IInventoryService invService = scene.InventoryService;
// Special case: folder redirect.
// RLV uses this
if (im.dialog == (byte) InstantMessageDialog.TaskInventoryAccepted)
{
InventoryFolderBase folder = invService.GetFolder(client.AgentId, inventoryID);
if (folder != null)
{
if (im.binaryBucket.Length >= 16)
{
UUID destFolderID = new UUID(im.binaryBucket, 0);
if (destFolderID != UUID.Zero)
{
InventoryFolderBase destFolder = invService.GetFolder(client.AgentId, destFolderID);
if (destFolder != null)
{
if (folder.ParentID != destFolder.ID)
{
folder.ParentID = destFolder.ID;
invService.MoveFolder(folder);
client.SendBulkUpdateInventory(folder);
}
}
}
}
}
}
ScenePresence user = scene.GetScenePresence(new UUID(im.toAgentID)); ScenePresence user = scene.GetScenePresence(new UUID(im.toAgentID));
if (user != null) // Local if (user != null) // Local
{ {
user.ControllingClient.SendInstantMessage(im); user.ControllingClient.SendInstantMessage(im);
@ -307,121 +281,114 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
} }
else if (im.dialog == (byte) InstantMessageDialog.TaskInventoryAccepted) else if (im.dialog == (byte) InstantMessageDialog.TaskInventoryAccepted)
{ {
UUID destinationFolderID = UUID.Zero; if (im.binaryBucket == null || im.binaryBucket.Length < 16)
return;
if (im.binaryBucket != null && im.binaryBucket.Length >= 16) UUID destinationFolderID = new UUID(im.binaryBucket, 0);
destinationFolderID = new UUID(im.binaryBucket, 0); if(destinationFolderID == UUID.Zero) // uuid-zero is a valid folder ID(?) keeping old code assuming not
return;
IInventoryService invService = scene.InventoryService; IInventoryService invService = scene.InventoryService;
InventoryFolderBase destinationFolder = null; InventoryFolderBase destinationFolder = null;
if (destinationFolderID != UUID.Zero) destinationFolder = invService.GetFolder(agentID, destinationFolderID);
destinationFolder = invService.GetFolder(client.AgentId, destinationFolderID);
if(destinationFolder != null) if(destinationFolder == null)
{ return; // no where to put it
UUID inventoryID = new UUID(im.imSessionID); // The inventory item/folder, back from it's trip
InventoryItemBase item = invService.GetItem(client.AgentId, inventoryID);
InventoryFolderBase folder = null;
UUID? previousParentFolderID = null;
if (item != null) // It's an item
{
if(item.Folder != destinationFolderID)
{
previousParentFolderID = item.Folder;
item.Folder = destinationFolderID;
invService.MoveItems(item.Owner, new List<InventoryItemBase>() { item });
client.SendInventoryItemCreateUpdate(item, 0);
}
}
else
{
folder = invService.GetFolder(client.AgentId, inventoryID);
if (folder != null) // It's a folder
{
if(folder.ParentID != destinationFolderID)
{
previousParentFolderID = folder.ParentID;
folder.ParentID = destinationFolderID;
invService.MoveFolder(folder);
}
}
}
// Tell client about updates to original parent and new parent (this should probably be factored with existing move item/folder code).
if (previousParentFolderID != null)
{
InventoryFolderBase previousParentFolder = invService.GetFolder(client.AgentId, (UUID)previousParentFolderID);
scene.SendInventoryUpdate(client, previousParentFolder, true, true);
scene.SendInventoryUpdate(client, destinationFolder, true, true);
}
}
}
else if (
im.dialog == (byte)InstantMessageDialog.InventoryDeclined
|| im.dialog == (byte)InstantMessageDialog.TaskInventoryDeclined)
{
// Here, the recipient is local and we can assume that the
// inventory is loaded. Courtesy of the above bulk update,
// It will have been pushed to the client, too
//
IInventoryService invService = scene.InventoryService;
InventoryFolderBase trashFolder =
invService.GetFolderForType(client.AgentId, FolderType.Trash);
UUID inventoryID = new UUID(im.imSessionID); // The inventory item/folder, back from it's trip UUID inventoryID = new UUID(im.imSessionID); // The inventory item/folder, back from it's trip
if(inventoryID == UUID.Zero)
return;
InventoryItemBase item = invService.GetItem(client.AgentId, inventoryID); InventoryItemBase item = invService.GetItem(agentID, inventoryID);
InventoryFolderBase folder = null; InventoryFolderBase folder = null;
UUID? previousParentFolderID = null; UUID? previousParentFolderID = null;
if (item != null && trashFolder != null) if (item != null) // It's an item
{ {
previousParentFolderID = item.Folder; if(item.Folder != destinationFolderID)
item.Folder = trashFolder.ID; {
item.Folder = destinationFolderID;
// Diva comment: can't we just update this item??? invService.MoveItems(item.Owner, new List<InventoryItemBase>() { item });
List<UUID> uuids = new List<UUID>(); client.SendInventoryItemCreateUpdate(item, 0);
uuids.Add(item.ID); }
invService.DeleteItems(item.Owner, uuids);
scene.AddInventoryItem(client, item);
} }
else else
{ {
folder = invService.GetFolder(client.AgentId, inventoryID); folder = invService.GetFolder(agentID, inventoryID);
if (folder != null && trashFolder != null) if (folder != null) // It's a folder
{ {
previousParentFolderID = folder.ParentID; if(folder.ParentID != destinationFolderID)
folder.ParentID = trashFolder.ID; {
invService.MoveFolder(folder); previousParentFolderID = folder.ParentID;
client.SendBulkUpdateInventory(folder); folder.ParentID = destinationFolderID;
invService.MoveFolder(folder);
}
} }
} }
if ((null == item && null == folder) || null == trashFolder)
{
string reason = String.Empty;
if (trashFolder == null)
reason += " Trash folder not found.";
if (item == null)
reason += " Item not found.";
if (folder == null)
reason += " Folder not found.";
client.SendAgentAlertMessage("Unable to delete "+
"received inventory" + reason, false);
}
// Tell client about updates to original parent and new parent (this should probably be factored with existing move item/folder code). // Tell client about updates to original parent and new parent (this should probably be factored with existing move item/folder code).
else if (previousParentFolderID != null) if (previousParentFolderID != null)
{ {
InventoryFolderBase previousParentFolder = invService.GetFolder(client.AgentId, (UUID)previousParentFolderID); InventoryFolderBase previousParentFolder = invService.GetFolder(agentID, previousParentFolderID.Value);
scene.SendInventoryUpdate(client, previousParentFolder, true, true); if(previousParentFolder != null)
scene.SendInventoryUpdate(client, previousParentFolder, true, true);
scene.SendInventoryUpdate(client, destinationFolder, true, true);
}
}
else if (im.dialog == (byte)InstantMessageDialog.InventoryDeclined ||
im.dialog == (byte)InstantMessageDialog.TaskInventoryDeclined)
{
IInventoryService invService = scene.InventoryService;
InventoryFolderBase trashFolder = invService.GetFolderForType(agentID, FolderType.Trash);
if(trashFolder == null) //??
{
client.SendAgentAlertMessage("Trash folder not found", false);
return;
}
UUID inventoryID = new UUID(im.imSessionID); // The inventory item/folder, back from it's trip
if(inventoryID == UUID.Zero)
{
client.SendAgentAlertMessage("Item or folder not found", false);
return;
}
InventoryItemBase item = invService.GetItem(agentID, inventoryID);
InventoryFolderBase folder = null;
UUID? previousParentFolderID = null;
if (item != null)
{
if (trashFolder.ID != item.Folder)
{
item.Folder = trashFolder.ID;
invService.MoveItems(item.Owner, new List<InventoryItemBase>() { item });
client.SendInventoryItemCreateUpdate(item, 0);
}
}
else
{
folder = invService.GetFolder(agentID, inventoryID);
if (folder != null)
{
if (trashFolder.ID != folder.ParentID)
{
previousParentFolderID = folder.ParentID;
folder.ParentID = trashFolder.ID;
invService.MoveFolder(folder);
client.SendBulkUpdateInventory(folder);
}
}
}
// Tell client about updates to original parent and new parent (this should probably be factored with existing move item/folder code).
if (previousParentFolderID != null)
{
InventoryFolderBase previousParentFolder = invService.GetFolder(agentID, (UUID)previousParentFolderID);
if(previousParentFolder != null)
scene.SendInventoryUpdate(client, previousParentFolder, true, true);
scene.SendInventoryUpdate(client, trashFolder, true, true); scene.SendInventoryUpdate(client, trashFolder, true, true);
} }