internal InventoryLandmark NewLandmark(string Name, string Description, LLUUID FolderID) { InventoryLandmark iLandmark = new InventoryLandmark(this, Name, Description, FolderID, slClient.Network.AgentID); // Create this notecard on the server. ItemCreate(iLandmark); return iLandmark; }
/// <summary> /// Returned in response to a FetchInventoryDescendents request. Contains information about the /// contents of a folder. /// </summary> /// <param name="packet"></param> /// <param name="simulator"></param> public void InventoryDescendentsHandler(Packet packet, Simulator simulator) { InventoryDescendentsPacket reply = (InventoryDescendentsPacket)packet; // The UUID of this folder. LLUUID uuidFolderID = reply.AgentData.FolderID; // Wait until it's safe to be looking at what is currently downloading. CurrentlyDownloadingMutex.WaitOne(); // Make sure this request matches the one we believe is the currently downloading request if (((CurrentlyDownloadingRequest != null) && (CurrentlyDownloadingRequest.FolderID != uuidFolderID)) || (CurrentlyDownloadingRequest == null)) { // Release so that we can let other things look at and modify what is currently downloading. CurrentlyDownloadingMutex.ReleaseMutex(); // Log problem LogDescendantQueueEvent("Unexpected descendent packet for folder: " + uuidFolderID.ToStringHyphenated()); // Just discard this packet... return; } // Get the Inventory folder that we'll be updating InventoryFolder InvFolderUpdating = (InventoryFolder)FoldersByUUID[uuidFolderID]; // Update Inventory Manager's last tick point, used for timeouts and such // LastPacketRecievedAtTick = Environment.TickCount; // Used to count the number of descendants received to see if we're finished or not. int iDescendentsExpected = reply.AgentData.Descendents; int iDescendentsReceivedThisBlock = 0; #region Handle Child Items foreach (InventoryDescendentsPacket.ItemDataBlock itemBlock in reply.ItemData) { // There is always an item block, even if there isn't any items // the "filler" block will not have a name if (itemBlock.Name.Length != 0) { iDescendentsReceivedThisBlock++; if (itemBlock.ItemID == LLUUID.Zero) { // this shouldn't ever happen, unless you've uploaded an invalid item // to yourself while developping inventory code :-( } else { InventoryItem TempInvItem = new InventoryItem(this, itemBlock); if (InvFolderUpdating._Contents.Contains(TempInvItem) == false) { #region Create an instance of the appriopriate Inventory class if ((TempInvItem.InvType == 7) && (TempInvItem.Type == (sbyte)Asset.AssetType.Notecard)) { InventoryItem temp = new InventoryNotecard(this, TempInvItem); TempInvItem = temp; } if ((TempInvItem.InvType == 3) && (TempInvItem.Type == (sbyte)Asset.AssetType.Landmark)) { InventoryItem temp = new InventoryLandmark(this, TempInvItem); TempInvItem = temp; } if ((TempInvItem.InvType == 0) && (TempInvItem.Type == (sbyte)Asset.AssetType.Texture)) { InventoryItem temp = new InventoryImage(this, TempInvItem); TempInvItem = temp; } if ((TempInvItem.InvType == 10) && (TempInvItem.Type == (sbyte)Asset.AssetType.LSLText)) { InventoryItem temp = new InventoryScript(this, TempInvItem); TempInvItem = temp; } if ((TempInvItem.InvType == 18) && ( (TempInvItem.Type == (sbyte)Asset.AssetType.Bodypart) || (TempInvItem.Type == (sbyte)Asset.AssetType.Clothing) ) ) { InventoryItem temp = new InventoryWearable(this, TempInvItem); TempInvItem = temp; } #endregion InvFolderUpdating._Contents.Add(TempInvItem); } } } } #endregion #region Handle Child Folders foreach (InventoryDescendentsPacket.FolderDataBlock folderBlock in reply.FolderData) { String IncomingName = System.Text.Encoding.UTF8.GetString(folderBlock.Name).Trim().Replace("\0", ""); LLUUID IncomingFolderID = folderBlock.FolderID; LLUUID IncomingParentID = folderBlock.ParentID; sbyte IncomingType = folderBlock.Type; // There is always an folder block, even if there isn't any folders // the "filler" block will not have a name if (folderBlock.Name.Length != 0) { iDescendentsReceivedThisBlock++; // See if the Incoming Folder already exists locally if (FoldersByUUID.ContainsKey(IncomingFolderID)) { InventoryFolder existingFolder = FoldersByUUID[IncomingFolderID]; existingFolder._Name = IncomingName; existingFolder._Type = IncomingType; // Check if parent of existing is the same as the incoming if (!existingFolder.ParentID.Equals(IncomingParentID)) { // Remove existing from old parent if (FoldersByUUID.ContainsKey(existingFolder.ParentID)) { InventoryFolder ExistingParent = FoldersByUUID[existingFolder.ParentID]; if (ExistingParent._Contents.Contains(existingFolder)) { ExistingParent._Contents.Remove(existingFolder); } } // Set existings parent to new existingFolder._ParentID = IncomingParentID; // Connect existing folder to parent specified in new if (FoldersByUUID.ContainsKey(IncomingParentID)) { InventoryFolder ExistingParent = FoldersByUUID[IncomingParentID]; if (!ExistingParent._Contents.Contains(existingFolder)) { ExistingParent._Contents.Add(existingFolder); } } } } else { InventoryFolder TempInvFolder = new InventoryFolder(this, IncomingName, IncomingFolderID, IncomingParentID, IncomingType); // Add folder to Parent if (InvFolderUpdating._Contents.Contains(TempInvFolder) == false) { InvFolderUpdating._Contents.Add(TempInvFolder); } // Add folder to local cache lookup FoldersByUUID[TempInvFolder.FolderID] = TempInvFolder; } // Do we recurse? if (CurrentlyDownloadingRequest.Recurse) { // It's not the root, should be safe to "recurse" if (!IncomingFolderID.Equals(slClient.Self.InventoryRootFolderUUID)) { FolderRequestPrepend(IncomingFolderID, CurrentlyDownloadingRequest.Recurse, CurrentlyDownloadingRequest.FetchFolders, CurrentlyDownloadingRequest.FetchItems, CurrentlyDownloadingRequest.Name + "/" + IncomingName); } } } } #endregion // Update total number of descendants expected , and update the total downloaded CurrentlyDownloadingRequest.Expected = iDescendentsExpected; CurrentlyDownloadingRequest.Received += iDescendentsReceivedThisBlock; CurrentlyDownloadingRequest.LastReceivedAtTick = Environment.TickCount; if ((iDescendentsExpected > 1) && (iDescendentsReceivedThisBlock == 0)) { slClient.Log("Received an InventoryDescendant packet where it indicated that there should be at least 1 descendant, but none were present... [" + CurrentlyDownloadingRequest.Name + "]", Helpers.LogLevel.Warning); CurrentlyDownloadingRequest.Expected = 0; } if (LogDescendantQueue) { slClient.Log("Received packet for: " + CurrentlyDownloadingRequest.ToString(), Helpers.LogLevel.Info); } // Check if we're finished if (CurrentlyDownloadingRequest.Received >= CurrentlyDownloadingRequest.Expected) { LogDescendantQueueEvent("Done downloading request: " + CurrentlyDownloadingRequest); // Singal anyone that was waiting for this request to finish CurrentlyDownloadingRequest.RequestComplete.Set(); // Raise an event for anyone that cares to listen for downloaded folder events if (OnRequestDownloadFinishedEvent != null) { DownloadRequest_EventArgs e = new DownloadRequest_EventArgs(); e.DownloadRequest = CurrentlyDownloadingRequest; FireRequestDownloadFinishedEvent(InvFolderUpdating, e); } // Set Inventory Manager state to reflect that we're done with the current download CurrentlyDownloadingAFolder = false; CurrentlyDownloadingRequest = null; } // Release so that we can let other things look at and modify what is currently downloading. CurrentlyDownloadingMutex.ReleaseMutex(); // If there's any more download requests queued, grab one, and go FolderRequestBegin(); }