# EOS 大厅集成

本指南将向您展示如何在 Unreal 游戏项目中将 Edgegap 与 EOS 大厅集成在一起工作。某些步骤需要您使用令牌向我们的 API 发送请求， `curl` 下面提供的命令将允许您预览每个响应，以便确定如何在代码中处理它们。在请求中使用令牌时，请确保保管好 `令牌` 关键字。

您还需要在我们的平台上为项目设置一个应用版本。在这种情况下，我们建议使用 Edgegap Unreal 插件以加快测试过程。有关该插件的更多信息，您可以阅读我们的文档 [这里](broken://pages/8ce884b50af41f14b967cc337666e5bbeca3dab3).

{% hint style="warning" %}
作为一项安全措施，不建议在生产环境中由 EOS 大厅所有者直接将请求发送到 Edgegap API，因为客户端会获取到 API 令牌。您应改为使用单独的服务来管理这些请求。
{% endhint %}

### 1. 获取并存储玩家的公网 IP

首先，每位加入大厅的玩家——包括大厅所有者——都需要获取他们的公网 IP 并将其存储为 [大厅成员属性](https://dev.epicgames.com/docs/game-services/lobbies#lobby-and-lobby-member-properties).

```
curl --location --request GET 'https://api.edgegap.com/v1/ip' \
--header 'Authorization: [EDGEGAP_API_TOKEN]'
```

### 2. 创建部署

一旦大厅所有者决定比赛准备就绪，需要发送请求在 Edgegap 上创建一个新的部署，使用先前存储的公网 IP 列表。

```
curl --location --request POST 'https://api.edgegap.com/v1/deploy' \
--header 'Content-Type: application/json' \
--header 'Authorization: [EDGEGAP_API_TOKEN]' \
--data-raw '{
    "app_name": "[EDGEGAP_APP_NAME]",
    "version_name": "[EDGEGAP_APP_VERSION]",
    "ip_list": [
        "[LOBBY_MEMBER_IP]"
    ]
}'
```

之后，大厅所有者需要使用部署创建请求响应中提供的 request\_id 不断轮询该部署。一旦回复中部署的 `current_status` 设置为 `READY`，大厅所有者需要将部署的 IP 和端口值设置为 [EOS 大厅属性](https://dev.epicgames.com/docs/game-services/lobbies#lobby-and-lobby-member-properties).

```
curl --location --request GET 'https://api.edgegap.com/v1/status/[REQUEST_ID]' \
--header 'Authorization: [EDGEGAP_API_TOKEN]'
```

### 3. 连接到部署

当玩家收到已分配 IP 和端口值的通知后，他们可以将其与客户端缓存进行比较，然后使用这些值连接到服务器以进行比赛。

### 4. 结束比赛与部署

比赛结束后，大厅所有者将从 EOS 大厅属性中取消设置 IP 和端口值，这会通知其他所有人从服务器优雅断开连接。如果应用配置为注入环境变量，则可以在此时使用这些变量从应用内部终止部署。

要从服务器外部终止部署，可以改为使用如下所示的 `curl` 命令。

```
curl --location --request DELETE 'https://api.edgegap.com/v1/stop/[REQUEST_ID]' \
--header 'Authorization: [EDGEGAP_API_TOKEN]'
```

如果玩家仍然留在大厅，大厅所有者可以从请求新部署开始重复这些步骤，以便与相同的人发起重赛。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.edgegap.com/zh/docs/tools-and-integrations/unreal-eos-lobby-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
