Benthic Logo

Optional

This component is an optional feature in the metaverse_client crate. Projects that don't require this can compile with the feature disabled in Cargo.toml

Inventory

The inventory is a core part of metaverse servers. This manages the objects your user owns and can spawn in the world.

Implementing inventory requires using the FetchInventoryDescendents2 endpoint. If you are unfamiliar with how capabilities work, visit the capabilities page on these docs.

1.

Initial Inventory information comes in with the LoginResponse, and is stored globally in the session.

2.

The initialization function triggers a RefreshInventoryEvent for the user's AgentID which is also returned from the LoginResponse. The initial request is a request for the user's inventory.

3.

The RefreshInventoryEvent waits until the capability URL has returned from the initial capability request.

4.

Make a request to the capability endpoint, using the sesion's inventory_root to make a FolderRequest, to make a request to refresh the user's inventory.

5.

Establish_inventory_dirs() creates folders on disk to represent the user's inventory structure, and handles the item metadata. It then recursively calls refresh_inventory() on each of the subdirectories, creating more FolderRequests to the capability endpoint.

Item Metadata

The establish_inventory_dirs() function reads the folder data and generates the objects received from the endpoint here.

The Folder::from_llsd() function prarses the LLSD-XML and retreives the item metadata from the LLSD. This contains a minimal amount of information about the item object, such as the permissions, name, asset ID, description and type. These fields can be used to retreive the full item's data from the server using a different endpoint, and are saved to the session under the Folder object.
At this point, the inventory's directory structure is populated, and contains the user's inventory objects. The folders are stored on-disk in a sqlite DB, which can be searched quickly without having to waste RAM on the folder structure.

Folder Requests

The user's folders are requested from the FetchInventoryDescendents2 endpoint, whereas other user's folders are requested from the FetchLibDescendents2 endpoint (for things like rendering other players' models).
The XML for the request is structured like so
Folder
fetch_folders boolean
fetch_items boolean
folder_id uuid
sort_order integer
owner_id uuid
For example, a request would look like this.
Post: http://172.20.20.20:9000/371320f6-7694-4e9c-bbb9-19e56f1e1027
Header: "Content-Type", "application/llsd+xml
<?xml version="1.0" encoding="UTF-8"?>
<llsd>
  <map>
    <key>folders</key>
    <array>
      <map>
        <key>fetch_folders</key>
        <boolean>true</boolean>
        <key>fetch_items</key>
        <boolean>true</boolean>
        <key>folder_id</key>
        <uuid>5b70e16b-4e8c-e463-f9b5-16e28f1b7213</uuid>
        <key>sort_order</key>
        <integer>0</integer>
        <key>owner_id</key>
        <uuid>fb2e5541-66ba-4019-a5de-e8b9286b0914</uuid>
      </map>
    </array>
  </map>
</llsd>