> ## 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.

# 加入大厅

> 使用大厅 ID、连接字符串或邀请来加入 PlayFab 大厅,并处理成员加入、初始属性和访问策略限制。

# 加入大厅和连接字符串

玩家通过向大厅服务提供大厅的“连接字符串”(一种不透明的标识符,用于授予大厅成员资格)来加入大厅。

玩家可以通过以下方式发现连接字符串并加入大厅。

1. 通过使用游戏内邀请—大厅成员可以通过大厅服务直接邀请另一位玩家加入该大厅。这会将该大厅的连接字符串共享给被邀请的玩家。这些邀请可以跨平台工作,但只在游戏内有效。有关更多信息,请参阅[大厅邀请](/services/playfab/multiplayer/lobby/lobby-invites)
2. 通过使用平台提供的邀请—大厅成员可以通过平台特定的邀请机制直接将大厅的连接字符串共享给其他玩家。这些邀请不能跨平台工作,但接收者无需已经在运行游戏即可收到。
3. 通过使用 [FindLobbies](/services/playfab/multiplayer/lobby/find-lobbies) 搜索可用大厅并加入其中之一
4. 通过任何带外自定义发现机制共享大厅的连接字符串

<Note>
  只有玩家(即 title\_player\_account PlayFab 实体)可以作为成员加入大厅。游戏服务器(即 game\_server PlayFab 实体)不能作为成员加入大厅。有关游戏服务器如何与大厅交互的更多信息,请参阅[游戏服务器与大厅](/services/playfab/multiplayer/lobby/lobby-server-overview)。
</Note>

## 连接字符串和大厅 ID

除连接字符串外,大厅还有一个称为 **LobbyId** 的标识符。**LobbyId** 是大厅的唯一标识符。游戏可以使用 **LobbyId** 来区分玩家所在的多个大厅,但 LobbyId 不能用于加入大厅或直接查询需要成员资格才能获取的任何信息。因此,你的游戏不必对 **LobbyId** 保密。相比之下,连接字符串授予对大厅的访问权,应注意不要将其暴露给不需要的外部方。

## 使用 Lobby 和 Matchmaking SDK 加入大厅示例

以下是一个简短的代码片段,演示了如何将连接字符串传递给 SDK 提供的 **PFMultiplayerJoinLobby** API。

在此代码片段中,连接字符串可以由上述任何发现机制提供:游戏内邀请、平台特定邀请或经过筛选的大厅搜索。

```cpp theme={null}
// Initialize the member properties for the newly joining member
const char* playerColorPropertyKey = "PlayerColor";
const char* playerColorPropertyValue = MyGame::GetPlayerColorString(localUser);

PFLobbyJoinConfiguration joinConfig;
joinConfig.memberPropertyCount = 1;
joinConfig.memberPropertyKeys = &playerColorPropertyKey;
joinConfig.memberPropertyValues = &playerColorPropertyValue;

// Join the lobby using the connection string
HRESULT hr = PFMultiplayerJoinLobby(
    g_pfmHandle,
    &localUser,
    connectionString,
    &joinConfig,
    nullptr,
    nullptr);
```

## 另请参阅

* [查找大厅](/services/playfab/multiplayer/lobby/find-lobbies)
* [创建可搜索的大厅](/services/playfab/multiplayer/lobby/define-search-keywords)
* [大厅与匹配](/services/playfab/multiplayer/lobby/lobby-and-matchmaking)
* [大厅属性](/services/playfab/multiplayer/lobby/lobby-properties)
* [创建大厅](/services/playfab/multiplayer/lobby/create-a-lobby)


## Related topics

- [从 MPSD 迁移到 PlayFab Multiplayer 和 MPA](/zh-CN/services/xbox-services/multiplayer/mpsd/concepts/live-mpsd-to-mlp.md)
- [Multiplayer Unity 插件快速入门](/zh-CN/services/playfab/multiplayer/lobby/lobby-matchmaking-sdks/multiplayer-unity-plugin-quickstart.md)
- [使用多人 SDK 将 Party 与 Lobby 集成](/zh-CN/services/playfab/multiplayer/networking/party-lobby-integration.md)
- [大厅邀请](/zh-CN/services/playfab/multiplayer/lobby/lobby-invites.md)
- [查找大厅](/zh-CN/services/playfab/multiplayer/lobby/find-lobbies.md)
