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

# 游戏服务器与大厅

> 通过启用服务器 API、验证 game_server 实体身份并创建或认领由服务器拥有的大厅,从专用游戏服务器使用 PlayFab 大厅。

本文介绍如何从游戏服务器使用 PlayFab 大厅。

## 在 PlayFab Multiplayer SDK 中启用游戏服务器 API

若要在 PlayFab Multiplayer 中启用游戏服务器 API,你必须在包含 PFLobby.h 之前定义 PFMULTIPLAYER\_INCLUDE\_SERVER\_APIS。

```cpp theme={null}
#define PFMULTIPLAYER_INCLUDE_SERVER_APIS
#include <PFMultiplayer.h>
#include <PFLobby.h>
```

## 创建由服务器拥有的大厅

若要创建由服务器拥有的大厅,请按以下步骤操作:

1. 使用 [AuthenticateGameServerWithCustomId](https://learn.microsoft.com/en-us/rest/api/playfab/authentication/authentication/authenticate-game-server-with-custom-id) 以 game\_server PlayFab 实体身份登录,并获取实体键和令牌对。
2. 使用 [PFMultiplayerSetEntityToken](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayer/functions/pfmultiplayersetentitytoken) 将 game\_server 的实体键和令牌提供给 PlayFab Multiplayer SDK。
3. 使用 game\_server 的实体键调用 [PFMultiplayerCreateAndClaimServerLobby](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/functions/pfmultiplayercreateandclaimserverlobby)。

有关更多信息和示例代码,请参阅[创建大厅](/services/playfab/multiplayer/lobby/create-a-lobby)。

## 服务器不是成员

在客户端所拥有的大厅中,大厅的所有者也是大厅的成员。

服务器所拥有的大厅在这方面有所不同。拥有大厅的 game\_server 实体不是大厅的成员。

服务器所有者能够修改全局大厅属性,但没有自己的成员属性部分。

有关这一区别的更多信息,请参阅[大厅所有者与成员](/services/playfab/multiplayer/lobby/owner-requirements-and-privileges)。

## 所有权与所有权迁移策略

与客户端所拥有的大厅不同,对于服务器所拥有的大厅,只有一种有效的所有权迁移策略:“Server”所有权迁移策略。

这对所有权迁移和大厅恢复有重要影响。

主要而言,当服务器所拥有大厅的所有者断开连接时(例如服务器崩溃),大厅的所有权不会自动转移给大厅中的任何成员。相反,该大厅会在大厅搜索结果中隐藏(以避免新成员无意加入此大厅),并由游戏来协调某种恢复逻辑。

在下一个可用的机会,崩溃的 game\_server 实体应通过 [PFMultiplayerFindLobbies](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/functions/pfmultiplayerfindlobbies) 使用 [lobby/amOwner 搜索键](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/constants/pflobbysearchkeys)搜索需要恢复的大厅。

在找到需要恢复的大厅后,游戏服务器可以尝试恢复游戏会话或删除该大厅。

有关所有权变更的更多信息,请参阅[所有权变更](/services/playfab/multiplayer/lobby/ownership-changes)。

## 另请参阅

* [创建大厅](/services/playfab/multiplayer/lobby/create-a-lobby)
* [大厅所有者与成员](/services/playfab/multiplayer/lobby/owner-requirements-and-privileges#lobby-owners-vs-members)
* [AuthenticateGameServerWithCustomId](https://learn.microsoft.com/en-us/rest/api/playfab/authentication/authentication/authenticate-game-server-with-custom-id)


## Related topics

- [大厅邀请](/zh-CN/services/playfab/multiplayer/lobby/lobby-invites.md)
- [创建大厅](/zh-CN/services/playfab/multiplayer/lobby/create-a-lobby.md)
- [大厅生命周期与过期](/zh-CN/services/playfab/multiplayer/lobby/lobby-ttl.md)
- [加入大厅](/zh-CN/services/playfab/multiplayer/lobby/join-lobbies.md)
- [PlayFab Multiplayer C++ SDK 发行说明](/zh-CN/services/playfab/multiplayer/lobby/lobby-matchmaking-sdks/lobby-and-matchmaking-release-notes.md)
