private static InventoryFolderBase GetCurrentOutfitFolder(CachedUserInfo userInfo)
            {
                // Duplicate method exists at Scene.Inventory.cs::Scene::GetCurrentOutfitFolder

                InventoryFolderBase currentOutfitFolder = null;

                try
                {
                    currentOutfitFolder = userInfo.FindFolderForType((int)AssetType.CurrentOutfitFolder);
                }
                catch (InventoryStorageException)
                {
                    // could not find it by type. load root and try to find it by name.
                    InventorySubFolderBase foundFolder = null;
                    InventoryFolderBase    rootFolder  = userInfo.FindFolderForType((int)AssetType.RootFolder);
                    foreach (var subfolder in rootFolder.SubFolders)
                    {
                        if (subfolder.Name == COF_NAME)
                        {
                            foundFolder = subfolder;
                            break;
                        }
                    }
                    if (foundFolder != null)
                    {
                        currentOutfitFolder = userInfo.GetFolder(foundFolder.ID);
                        if (currentOutfitFolder != null)
                        {
                            currentOutfitFolder.Level = InventoryFolderBase.FolderLevel.TopLevel;
                            userInfo.UpdateFolder(currentOutfitFolder);
                        }
                    }
                }
                if (currentOutfitFolder != null)
                {
                    currentOutfitFolder = userInfo.GetFolder(currentOutfitFolder.ID);
                }
                return(currentOutfitFolder);
            }
Пример #2
0
        private void TaskInventoryOfferDecline(IClientAPI client, Scene scene, GridInstantMessage im)
        {
            // The inventory item/folder, back from it's trip
            UUID inventoryEntityID = new UUID(im.imSessionID);

            // 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.
            CachedUserInfo userInfo = scene.CommsManager.UserService.GetUserDetails(client.AgentId);

            if (userInfo != null)
            {
                InventoryFolderBase trashFolder = userInfo.FindFolderForType((int)AssetType.TrashFolder);
                if (null == trashFolder)
                {
                    client.SendAgentAlertMessage("Unable to decline received inventory: Trash folder not found.", false);
                    return;
                }

                // Is it a folder or an item?
                if (userInfo.QueryItem(inventoryEntityID))
                {   // It's an item.
                    InventoryItemBase item = userInfo.FindItem(inventoryEntityID);
                    if (item == null)
                    {
                        client.SendAgentAlertMessage("Unable to decline received inventory: item/folder not found.", false);
                        return;
                    }
                    userInfo.MoveItemToTrash(item, trashFolder);
                    scene.AddInventoryItem(client, item);
                    client.SendInventoryItemCreateUpdate(item, 0);
                }
                else
                {   // It's a folder.
                    InventoryFolderBase folder = userInfo.GetFolderAttributes(inventoryEntityID);
                    userInfo.MoveFolder(inventoryEntityID, trashFolder.ID);
                    folder = userInfo.GetFolder(inventoryEntityID);
                    if (folder != null)
                    {
                        client.SendBulkUpdateInventory(folder);
                        // If we don't send the descendents, viewer shows "Loading..." on the trash item.
                        userInfo.SendInventoryDecendents(client, folder.ID, false, true);
                    }
                }
            }
        }
Пример #3
0
        private void OnInstantMessage(IClientAPI client, GridInstantMessage im)
        {
            m_log.InfoFormat("OnInstantMessage {0}", im.dialog);
            Scene scene = FindClientScene(client.AgentId);

            if (scene == null) // Something seriously wrong here.
            {
                return;
            }



            if (im.dialog == (byte)InstantMessageDialog.InventoryOffered)
            {
                //m_log.DebugFormat("Asset type {0}", ((AssetType)im.binaryBucket[0]));

                ScenePresence user = scene.GetScenePresence(new UUID(im.toAgentID));
                UUID          copyID;

                // First byte is the asset type
                AssetType assetType = (AssetType)im.binaryBucket[0];

                if (AssetType.Folder == assetType)
                {
                    UUID folderID = new UUID(im.binaryBucket, 1);

                    m_log.DebugFormat("[AGENT INVENTORY]: Inserting original folder {0} " +
                                      "into agent {1}'s inventory",
                                      folderID, new UUID(im.toAgentID));

                    InventoryFolderImpl folderCopy
                        = scene.GiveInventoryFolder(new UUID(im.toAgentID), client.AgentId, folderID, UUID.Zero);

                    if (folderCopy == null)
                    {
                        client.SendAgentAlertMessage("Can't find folder to give. Nothing given.", false);
                        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;
                    byte[] copyIDBytes = copyID.GetBytes();
                    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.IsChildAgent)
                    {
                        user.ControllingClient.SendBulkUpdateInventory(folderCopy);
                    }
                }
                else
                {
                    // First byte of the array is probably the item type
                    // Next 16 bytes are the UUID
                    m_log.Info("OnInstantMessage - giving item");

                    UUID itemID = new UUID(im.binaryBucket, 1);

                    m_log.DebugFormat("[AGENT INVENTORY]: Inserting item {0} " +
                                      "into agent {1}'s inventory",
                                      itemID, new UUID(im.toAgentID));

                    InventoryItemBase itemCopy = scene.GiveInventoryItem(
                        new UUID(im.toAgentID),
                        client.AgentId, itemID);

                    if (itemCopy == null)
                    {
                        client.SendAgentAlertMessage("Can't find item to give. Nothing given.", false);
                        return;
                    }

                    copyID = itemCopy.ID;
                    Array.Copy(copyID.GetBytes(), 0, im.binaryBucket, 1, 16);

                    if (user != null && !user.IsChildAgent)
                    {
                        user.ControllingClient.SendBulkUpdateInventory(itemCopy);
                    }
                }

                // Send the IM to the recipient. The item is already
                // in their inventory, so it will not be lost if
                // they are offline.
                //
                if (user != null && !user.IsChildAgent)
                {
                    // And notify. Transaction ID is the item ID. We get that
                    // same ID back on the reply so we know what to act on
                    //
                    user.ControllingClient.SendInstantMessage(im);

                    return;
                }
                else
                {
                    if (m_TransferModule != null)
                    {
                        m_TransferModule.SendInstantMessage(im, delegate(bool success) {});
                    }
                }
            }
            else if (im.dialog == (byte)InstantMessageDialog.InventoryAccepted)
            {
                ScenePresence user = scene.GetScenePresence(new UUID(im.toAgentID));

                if (user != null) // Local
                {
                    user.ControllingClient.SendInstantMessage(im);
                }
                else
                {
                    if (m_TransferModule != null)
                    {
                        m_TransferModule.SendInstantMessage(im, delegate(bool success) {});
                    }
                }
            }
            else if (im.dialog == (byte)InstantMessageDialog.InventoryDeclined)
            {
                // 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
                //

                CachedUserInfo userInfo =
                    scene.CommsManager.UserProfileCacheService.
                    GetUserDetails(client.AgentId);

                if (userInfo != null)
                {
                    InventoryFolderImpl trashFolder =
                        userInfo.FindFolderForType((int)AssetType.TrashFolder);

                    UUID inventoryEntityID = new UUID(im.imSessionID); // The inventory item/folder, back from it's trip

                    InventoryItemBase   item   = userInfo.RootFolder.FindItem(inventoryEntityID);
                    InventoryFolderBase folder = null;

                    if (item != null && trashFolder != null)
                    {
                        item.Folder = trashFolder.ID;

                        userInfo.DeleteItem(inventoryEntityID);

                        scene.AddInventoryItem(client, item);
                    }
                    else
                    {
                        folder = userInfo.RootFolder.FindFolder(inventoryEntityID);

                        if (folder != null & trashFolder != null)
                        {
                            userInfo.MoveFolder(inventoryEntityID, trashFolder.ID);
                        }
                    }

                    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);
                    }
                }

                ScenePresence user = scene.GetScenePresence(new UUID(im.toAgentID));

                if (user != null) // Local
                {
                    user.ControllingClient.SendInstantMessage(im);
                }
                else
                {
                    if (m_TransferModule != null)
                    {
                        m_TransferModule.SendInstantMessage(im, delegate(bool success) {});
                    }
                }
            }
        }