> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 创建可搜索的大厅

> 在 PlayFab 大厅上定义搜索键以及可搜索的字符串或数字属性,让玩家能够高效地筛选并发现公共游戏会话。

本文介绍如何创建可搜索的大厅。

若要使大厅可被搜索,其访问策略必须是 **Public** 或 **Friends**。具有 **Private** 访问策略的大厅无法从搜索查询中加入,必须通过[邀请](/services/playfab/multiplayer/lobby/lobby-invites)加入。通常在最初创建大厅时配置此访问策略。

一旦正确设置了大厅的访问策略,其他玩家就可以使用[查找大厅](/services/playfab/multiplayer/lobby/find-lobbies)搜索该大厅。

此外,大厅所有者可以定义自定义搜索属性,其他玩家在搜索大厅时可以使用这些属性来获得更精确的结果。

若要了解更多,请参阅[查找大厅](/services/playfab/multiplayer/lobby/find-lobbies)和[加入大厅](/services/playfab/multiplayer/lobby/join-lobbies)。

## 使用 Lobby 和 Matchmaking SDK 设置搜索属性示例

在此示例中,所创建的大厅定义了以下自定义搜索属性。

* 游戏模式 = "DeathMatch"
* 竞技风格 = "Ranked"
* 技能等级 = 创建大厅的玩家的技能等级

```cpp theme={null}
static PFMultiplayerHandle g_pfmHandle; // initialized elsewhere

#define PFLOBBY_SEARCH_KEY_GAME_MODE "string_key1"
#define PFLOBBY_SEARCH_KEY_COMPETITION_STYLE "string_key2"
#define PFLOBBY_SEARCH_KEY_SKILL "number_key1"

#define GAME_MODE_DEATH_MATCH "DeathMatch"
#define COMPETITION_STYLE_RANKED "Ranked"

PFEntityKey m_localUser;
namespace MyGame {
    uint32_t GetPlayerSkill(); // defined elsewhere
}

void CreateLobbyWithSearchProperties()
{
    // Initialize the lobby configuration with search properties
    std::string playerSkill = std::to_string(MyGame::GetPlayerSkill());

    const char* searchPropertyKeys[] = {
        PFLOBBY_SEARCH_KEY_GAME_MODE,
        PFLOBBY_SEARCH_KEY_COMPETITION_STYLE,
        PFLOBBY_SEARCH_KEY_SKILL,
    };

    const char* searchPropertyValues[_countof(searchPropertyKeys)] = {
        GAME_MODE_DEATH_MATCH,
        COMPETITION_STYLE_RANKED,
        playerSkill.c_str(),
    };

    PFLobbyCreateConfiguration lobbyConfiguration{};
    lobbyConfiguration.maxMemberCount = 16;
    lobbyConfiguration.searchPropertyCount = _countof(searchPropertyKeys);
    lobbyConfiguration.searchPropertyKeys = searchPropertyKeys;
    lobbyConfiguration.searchPropertyValues = searchPropertyValues;

    // Initialize an empty join configuration. This can be optionally initialized with the creator's member properties 
    PFLobbyJoinConfiguration creatorMemberConfiguration{};
    creatorMemberConfiguration.memberPropertyCount = 0;

    // Create and join the lobby
    PFLobbyHandle lobby;
    HRESULT hr = PFMultiplayerCreateAndJoinLobby(
        g_pfmHandle,
        &m_localUser,
        &lobbyConfiguration,
        &creatorMemberConfiguration,
        nullptr,
        &lobby);
}
```

## 另请参阅

* [查找大厅](/services/playfab/multiplayer/lobby/find-lobbies)
* [大厅属性](/services/playfab/multiplayer/lobby/lobby-properties)
* [所有者要求与特权](/services/playfab/multiplayer/lobby/owner-requirements-and-privileges)
* [创建大厅](/services/playfab/multiplayer/lobby/create-a-lobby)


## Related topics

- [创建大厅](/zh-CN/services/playfab/multiplayer/lobby/create-a-lobby.md)
- [查找大厅](/zh-CN/services/playfab/multiplayer/lobby/find-lobbies.md)
- [加入大厅](/zh-CN/services/playfab/multiplayer/lobby/join-lobbies.md)
- [大厅所有权变更](/zh-CN/services/playfab/multiplayer/lobby/ownership-changes.md)
- [PlayFab 大厅自定义属性](/zh-CN/services/playfab/multiplayer/lobby/lobby-properties.md)
