

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 适用于 Amazon GameLift Servers 4.x 的 C\$1\$1 服务器 SDK – 操作
<a name="integration-server-sdk-cpp-ref-actions"></a>

使用服务器 SDK 参考，将要托管的多人游戏与 Amazon GameLift Servers 集成。有关集成过程的指南，请参阅[借助服务器 SDK 将 Amazon GameLift Servers 添加到游戏服务器](gamelift-sdk-server-api.md)。

**注意**  
本参考适用于 Amazon GameLift Servers 服务器 SDK 的早期版本。有关最新版本，请参阅[适用于 Amazon GameLift Servers 的 C\$1\$1 服务器 SDK 5.x – 操作](integration-server-sdk5-cpp-actions.md)。

# 适用于 Amazon GameLift Servers 4.x 的 C\$1\$1 服务器 SDK – 数据类型
<a name="integration-server-sdk-cpp-ref-datatypes"></a>

使用服务器 SDK 参考，将要托管的多人游戏与 Amazon GameLift Servers 集成。有关集成过程的指南，请参阅[借助服务器 SDK 将 Amazon GameLift Servers 添加到游戏服务器](gamelift-sdk-server-api.md)。

**注意**  
本参考适用于 Amazon GameLift Servers 服务器 SDK 的早期版本。有关最新版本，请参阅[适用于 Amazon GameLift Servers 的 C\$1\$1 服务器 SDK 5.x – 数据类型](integration-server-sdk5-cpp-datatypes.md)。

此 API 在 `GameLiftServerAPI.h`、`LogParameters.h` 和 `ProcessParameters.h` 中定义。

[适用于 Amazon GameLift Servers 4.x 的 C\$1\$1 服务器 SDK – 操作](integration-server-sdk-cpp-ref-actions.md)

## DescribePlayerSessionsRequest
<a name="integration-server-sdk-cpp-ref-dataypes-playersessions"></a>

此数据类型用于指定检索哪些玩家会话。您可以按如下方式使用它：
+ 提供 a PlayerSessionId 以请求特定的玩家会话。
+ 提供 a GameSessionId 以请求指定游戏会话中的所有玩家会话。
+ 提供 a PlayerId 以请求指定玩家的所有玩家会话。

对于大型玩家会话集合，请使用分页参数以在有序数据块中检索结果。

### 内容
<a name="integration-server-sdk-cpp-ref-dataypes-playersessions-contents"></a>

**GameSessionId**  
游戏会话的唯一标识符。使用此参数可请求指定游戏会话的所有玩家会话。游戏会话 ID 的格式如下所示：`arn:aws:gamelift:<region>::gamesession/fleet-<fleet ID>/<ID string>`。<ID string> 的值为自定义 ID 字符串（如果在创建游戏会话时指定了一个）或者是生成的字符串。  
类型：字符串  
必需：否

**限制**  
要返回的最大结果数量。将此参数与一起*NextToken*使用可将结果作为一组连续页面获取。如果指定玩家会话 ID，将忽略此参数。  
类型：整数  
必需：否

**NextToken**  
令牌指示结果的下一个连续页面的开头。使用之前的调用返回此操作的令牌。要指定结果集的开始，请不要指定值。如果指定玩家会话 ID，将忽略此参数。  
类型：字符串  
必需：否

**PlayerId**  
玩家的唯一标识符。玩家 IDs 由开发者定义。请参阅[生成玩家 ID](player-sessions-player-identifiers.md)。  
类型：字符串  
必需：否

**PlayerSessionId**  
玩家会话的唯一标识符。  
类型：字符串  
必需：否

**PlayerSessionStatusFilter**  
用于筛选结果的玩家会话状态。可能的玩家会话状态包括以下内容：  
+ RESERVED — 已收到玩家会话请求，但玩家尚未连接到服务器进程 and/or 已通过验证。
+ ACTIVE - 服务器进程已验证玩家，当前已连接。
+ COMPLETED - 玩家连接已断开。
+ TIMEDOUT — 已收到玩家会话请求，但未在超时限制（60 秒）内验证未连接 and/or 的玩家。
类型：字符串  
必需：否

## LogParameters
<a name="integration-server-sdk-cpp-ref-dataypes-log"></a>

此数据类型用于标识您希望 Amazon GameLift Servers 在游戏会话结束时上传并存储游戏会话期间生成的哪些文件。此信息在 [ProcessReady()](integration-server-sdk-cpp-ref-actions.md#integration-server-sdk-cpp-ref-processready) 调用中传递给 Amazon GameLift Servers 服务。

### 内容
<a name="integration-server-sdk-cpp-ref-dataypes-log-contents"></a>

**logPaths**  
您希望 Amazon GameLift Servers 用于存储供以后访问的游戏服务器日志文件的目录路径。这些文件将在每个游戏会话期间生成。文件路径和名称在游戏服务器中定义并存储在根游戏构建目录中。日志路径必须是绝对的。例如，如果您的游戏构建在类似于 `MyGame\sessionlogs\` 的路径中存储游戏会话日志，则日志路径将为 `c:\game\MyGame\sessionLogs` (在 Windows 实例上) 或 `/local/game/MyGame/sessionLogs` (在 Linux 实例上)。  
类型：std:vector<std::string>  
必需：否

## ProcessParameters
<a name="integration-server-sdk-cpp-ref-dataypes-process"></a>

此数据类型包含一组在 [ProcessReady()](integration-server-sdk-cpp-ref-actions.md#integration-server-sdk-cpp-ref-processready) 调用中发送到 Amazon GameLift Servers 服务的参数。

### 内容
<a name="integration-server-sdk-cpp-ref-dataypes-process-contents"></a>

**端口**  
服务器进程用于侦听新玩家连接的端口号。该值必须在部署此游戏服务器构建的任意实例集上所配置的端口范围内。此端口号包含在游戏会话和玩家会话对象中，游戏会话在连接到服务器进程时会使用该端口号。  
类型：整数   
是否必需：是

**logParameters**  
包含游戏会话日志文件目录路径列表的对象。  
类型：Aws::GameLift:: 服务器:: [LogParameters](#integration-server-sdk-cpp-ref-dataypes-log)  
必需：否

**onStartGameSession**  
Amazon GameLift Servers服务为激活新游戏会话而调用的回调函数的名称。 Amazon GameLift Servers调用此函数是为了响应客户端的请求[CreateGameSession](https://docs.aws.amazon.com/gamelift/latest/apireference/API_CreateGameSession.html)。回调函数传递一个[GameSession](https://docs.aws.amazon.com/gamelift/latest/apireference/API_GameSession.html)对象（在*Amazon GameLift Servers服务 API 参考*中定义）。  
类型：`const std::function<void(Aws::GameLift::Model::GameSession)> onStartGameSession`  
是否必需：是

**onProcessTerminate**  
Amazon GameLift Servers 服务为强制关闭服务器进程而调用的回调函数的名称。调用此函数之后，Amazon GameLift Servers 等待五分钟以便服务器进程关闭，然后使用 [ProcessEnding()](integration-server-sdk-cpp-ref-actions.md#integration-server-sdk-cpp-ref-processending) 调用来进行响应。如果没有收到响应，它会关闭该服务器进程。  
类型：`std::function<void()> onProcessTerminate`  
必需：否

**onHealthCheck**  
Amazon GameLift Servers 服务为向服务器进程请求运行状况报告而调用的回调函数的名称。Amazon GameLift Servers 每隔 60 秒调用此函数一次。调用此函数后，Amazon GameLift Servers 将等待 60 秒接收响应，如果未收到响应，则会将服务器进程记录为不正常。  
类型：`std::function<bool()> onHealthCheck`  
必需：否

**onUpdateGameSession**  
Amazon GameLift Servers 服务为向服务器进程传递更新的游戏会话对象而调用的回调函数的名称。当[对战回填](https://docs.aws.amazon.com/gamelift/latest/flexmatchguide/match-backfill.html)请求处理完毕时，Amazon GameLift Servers 会调用此函数以提供更新的对战构建器数据。它将传递一个 [GameSession](https://docs.aws.amazon.com/gamelift/latest/apireference/API_GameSession.html) 对象、一个状态更新（`updateReason`）以及对战回填票证 ID。  
类型：`std::function<void(Aws::GameLift::Server::Model::UpdateGameSession)> onUpdateGameSession`  
必需：否

## StartMatchBackfillRequest
<a name="integration-server-sdk-cpp-ref-dataypes-startmatchbackfillrequest"></a>

此数据类型用于发送对战回填请求。此信息在 [StartMatchBackfill()](integration-server-sdk-cpp-ref-actions.md#integration-server-sdk-cpp-ref-startmatchbackfill) 调用中传递给 Amazon GameLift Servers 服务。

### 内容
<a name="integration-server-sdk-cpp-ref-dataypes-startbackfill-contents"></a>

**GameSessionArn**  
 游戏会话的唯一标识符。此 API 操作 [GetGameSessionId()](integration-server-sdk-cpp-ref-actions.md#integration-server-sdk-cpp-ref-getgamesessionid) 返回采用 ARN 格式的标识符。  
类型：字符串  
是否必需：是

**MatchmakingConfigurationArn**  
采用 ARN 格式的唯一标识符，适用于用于此请求的对战构建器。要查找用于创建原始游戏会话的对战构建器，请查看对战构建器数据属性中的游戏会话对象。[使用对战构建器数据](https://docs.aws.amazon.com/gamelift/latest/flexmatchguide/match-server.html#match-server-data)详细了解 Word 中的对战构建器数据。  
类型：字符串  
是否必需：是

**玩家**  
一组表示当前正在游戏会话中的所有玩家的数据。对战构建器使用此信息搜索与当前玩家非常匹配的新玩家。有关玩家对象格式的描述，请参阅《Amazon GameLift Servers API 参考指南》**。要查找玩家属性和团队分配，请在游戏会话对象的匹配器数据属性中查找。 IDs如果对战构建器使用了延迟，则收集当前区域中更新的延迟并将其包含在每个玩家的数据中。  
类型：std:vector[<Player>](https://docs.aws.amazon.com/gamelift/latest/apireference/API_Player.html)  
是否必需：是

**TicketId**  
对战或匹配回填请求票证的唯一标识符。如果此处未提供任何值，则 Amazon GameLift Servers 将生成一个采用 UUID 形式的值。使用此标识符可跟踪对战回填票证状态或取消请求（如需要）。  
类型：字符串  
必需：否

## StopMatchBackfillRequest
<a name="integration-server-sdk-cpp-ref-dataypes-stopmatchbackfillrequest"></a>

此数据类型用于取消对战回填请求。此信息在 [StopMatchBackfill()](integration-server-sdk-cpp-ref-actions.md#integration-server-sdk-cpp-ref-stopmatchbackfill) 调用中传递给 Amazon GameLift Servers 服务。

### 内容
<a name="integration-server-sdk-cpp-ref-dataypes-stopbackfill-contents"></a>

**GameSessionArn**  
与被取消的请求关联的唯一游戏会话标识符。  
类型：字符串  
是否必需：是

**MatchmakingConfigurationArn**  
此请求发送到的对战构建器的唯一标识符。  
类型：字符串  
是否必需：是

**TicketId**  
要取消的回填请求票证的唯一标识符。  
类型：字符串  
是否必需：是

[适用于 Amazon GameLift Servers 4.x 的 C\$1\$1 服务器 SDK – 数据类型](integration-server-sdk-cpp-ref-datatypes.md)

**Topics**
+ [适用于 Amazon GameLift Servers 4.x 的 C\$1\$1 服务器 SDK – 数据类型](integration-server-sdk-cpp-ref-datatypes.md)
+ [AcceptPlayerSession()](#integration-server-sdk-cpp-ref-acceptplayersession)
+ [ActivateGameSession()](#integration-server-sdk-cpp-ref-activategamesession)
+ [DescribePlayerSessions()](#integration-server-sdk-cpp-ref-describeplayersessions)
+ [GetGameSessionId()](#integration-server-sdk-cpp-ref-getgamesessionid)
+ [GetInstanceCertificate()](#integration-server-sdk-cpp-ref-getinstancecertificate)
+ [GetSdkVersion()](#integration-server-sdk-cpp-ref-getsdk)
+ [GetTerminationTime()](#integration-server-sdk-cpp-ref-getterm)
+ [InitSDK()](#integration-server-sdk-cpp-ref-initsdk)
+ [ProcessEnding()](#integration-server-sdk-cpp-ref-processending)
+ [ProcessReady()](#integration-server-sdk-cpp-ref-processready)
+ [ProcessReadyAsync()](#integration-server-sdk-cpp-ref-processreadyasync)
+ [RemovePlayerSession()](#integration-server-sdk-cpp-ref-removeplayersession)
+ [StartMatchBackfill()](#integration-server-sdk-cpp-ref-startmatchbackfill)
+ [StopMatchBackfill()](#integration-server-sdk-cpp-ref-stopmatchbackfill)
+ [TerminateGameSession()](#integration-server-sdk-cpp-ref-terminategamesession)
+ [UpdatePlayerSessionCreationPolicy()](#integration-server-sdk-cpp-ref-updateplayersessioncreationpolicy)
+ [Destroy](#integration-server-sdk-cpp-ref-destroy)

## AcceptPlayerSession()
<a name="integration-server-sdk-cpp-ref-acceptplayersession"></a>

通知 Amazon GameLift Servers 服务，具有所指定玩家会话 ID 的玩家已连接到服务器进程并且需要验证。Amazon GameLift Servers 将验证该玩家会话 ID 是否有效，即该玩家 ID 是否已在游戏会话中预留玩家位置。通过验证后，Amazon GameLift Servers 将玩家位置的状态从 RESERVED 更改为 ACTIVE。

### 语法
<a name="integration-server-sdk-cpp-ref-acceptplayersession-syntax"></a>

```
GenericOutcome AcceptPlayerSession(const std::string& playerSessionId);
```

### 参数
<a name="integration-server-sdk-cpp-ref-acceptplayersession-parameter"></a>

**playerSessionId**  
Amazon GameLift Servers服务为响应 AWS SDK Amazon GameLift Servers API 操作调用而颁发的唯一 ID [CreatePlayerSession](https://docs.aws.amazon.com/gamelift/latest/apireference/API_CreatePlayerSession.html)。连接到服务器进程时，游戏客户端会引用此 ID。  
类型：std:: string  
是否必需：是

### 返回值
<a name="integration-server-sdk-cpp-ref-acceptplayersession-return"></a>

返回由成功或失败组成的通用结果，并显示错误消息。

### 示例
<a name="integration-server-sdk-cpp-ref-acceptplayersession-example"></a>

此示例说明了处理连接请求的函数，包括验证和拒绝无效的玩家会话。 IDs

```
void ReceiveConnectingPlayerSessionID (Connection& connection, const std::string& playerSessionId){
    Aws::GameLift::GenericOutcome connectOutcome = 
        Aws::GameLift::Server::AcceptPlayerSession(playerSessionId);
    if(connectOutcome.IsSuccess())
    {
        connectionToSessionMap.emplace(connection, playerSessionId);
        connection.Accept();
    }
    else 
    {
        connection.Reject(connectOutcome.GetError().GetMessage();
    }       
}
```

## ActivateGameSession()
<a name="integration-server-sdk-cpp-ref-activategamesession"></a>

通知 Amazon GameLift Servers 服务，服务器进程已启动游戏会话，现在已准备好接收玩家连接。此操作应作为 `onStartGameSession()` 回调函数的一部分，在所有游戏会话初始化已完成之后调用。

### 语法
<a name="integration-server-sdk-cpp-ref-activategamesession-syntax"></a>

```
GenericOutcome ActivateGameSession();
```

### 参数
<a name="integration-server-sdk-cpp-ref-activategamesession-parameter"></a>

此操作没有参数。

### 返回值
<a name="integration-server-sdk-cpp-ref-activategamesession-return"></a>

返回由成功或失败组成的通用结果，并显示错误消息。

### 示例
<a name="integration-server-sdk-cpp-ref-activategamesession-example"></a>

此示例显示作为 `onStartGameSession()` 回调函数的一部分调用 `ActivateGameSession()`。

```
void onStartGameSession(Aws::GameLift::Model::GameSession myGameSession)
{
   // game-specific tasks when starting a new game session, such as loading map
   GenericOutcome outcome = Aws::GameLift::Server::ActivateGameSession();
}
```

## DescribePlayerSessions()
<a name="integration-server-sdk-cpp-ref-describeplayersessions"></a>

检索玩家会话数据，包括设置、会话元数据和玩家数据。使用此操作获取单个玩家会话的信息、游戏会话中所有玩家会话的信息或者与单个玩家 ID 相关联的所有玩家会话的信息。

### 语法
<a name="integration-server-sdk-cpp-ref-describeplayersessions-syntax"></a>

```
DescribePlayerSessionsOutcome DescribePlayerSessions ( 
    const Aws::GameLift::Server::Model::DescribePlayerSessionsRequest &describePlayerSessionsRequest);
```

### 参数
<a name="integration-server-sdk-cpp-ref-describeplayersessions-parameter"></a>

**describePlayerSessions请求**  
[DescribePlayerSessionsRequest](integration-server-sdk-cpp-ref-datatypes.md#integration-server-sdk-cpp-ref-dataypes-playersessions) 对象描述要检索的玩家会话。  
是否必需：是

### 返回值
<a name="integration-server-sdk-cpp-ref-describeplayersessions-return"></a>

如果成功，将返回一个 `DescribePlayerSessionsOutcome` 对象，包含一组与请求参数相匹配的玩家会话对象。玩家会话对象的结构与 AWS SDK Amazon GameLift Servers API [PlayerSession](https://docs.aws.amazon.com/gamelift/latest/apireference/API_PlayerSession.html)数据类型相同。

### 示例
<a name="integration-server-sdk-cpp-ref-describeplayersessions-example"></a>

此示例演示了将所有玩家会话主动连接到指定游戏会话的请求。通过忽略 `NextToken` 和将 `Limit` 值设置为 10，Amazon GameLift Servers 将返回符合请求条件的前 10 条玩家会话记录。

```
// Set request parameters
Aws::GameLift::Server::Model::DescribePlayerSessionsRequest request;
request.SetPlayerSessionStatusFilter(Aws::GameLift::Server::Model::PlayerSessionStatusMapper::GetNameForPlayerSessionStatus(Aws::GameLift::Server::Model::PlayerSessionStatus::Active));
request.SetLimit(10);
request.SetGameSessionId("the game session ID");    // can use GetGameSessionId()

// Call DescribePlayerSessions
Aws::GameLift::DescribePlayerSessionsOutcome playerSessionsOutcome = 
    Aws::GameLift::Server::DescribePlayerSessions(request);
```

## GetGameSessionId()
<a name="integration-server-sdk-cpp-ref-getgamesessionid"></a>

检索当前由服务器进程托管的游戏会话的唯一标识符 (如果服务器进程处于活动状态)。该标识符以 ARN 格式返回：`arn:aws:gamelift:<region>::gamesession/fleet-<fleet ID>/<ID string>`。

对于尚未通过游戏会话激活的空闲进程，该调用返回 `Success` = `True` 和 `GameSessionId` =`""`（空字符串）。

### 语法
<a name="integration-server-sdk-cpp-ref-getgamesessionid-syntax"></a>

```
AwsStringOutcome GetGameSessionId();
```

### 参数
<a name="integration-server-sdk-cpp-ref-getgamesessionid-parameter"></a>

此操作没有参数。

### 返回值
<a name="integration-server-sdk-cpp-ref-getgamesessionid-return"></a>

如果成功，以 `AwsStringOutcome` 对象返回游戏会话 ID。如果不成功，将返回错误消息。

### 示例
<a name="integration-server-sdk-cpp-ref-getgamesessionid-example"></a>

```
Aws::GameLift::AwsStringOutcome sessionIdOutcome = 
    Aws::GameLift::Server::GetGameSessionId();
```

## GetInstanceCertificate()
<a name="integration-server-sdk-cpp-ref-getinstancecertificate"></a>

检索与队列及其实例关联的 PEM 编码 TLS 证书的文件位置。 AWS Certificate Manager 当您在证书配置设置为 GENERATED 的情况下创建新队列时，将生成此证书。使用此证书可与游戏客户端建立安全连接并加密客户端/服务器通信。

### 语法
<a name="integration-server-sdk-cpp-ref-getinstancecertificate-syntax"></a>

```
GetInstanceCertificateOutcome GetInstanceCertificate();
```

### 参数
<a name="integration-server-sdk-cpp-ref-getinstancecertificate-parameter"></a>

此操作没有参数。

### 返回值
<a name="integration-server-sdk-cpp-ref-getinstancecertificate-return"></a>

如果成功，则返回一个 `GetInstanceCertificateOutcome` 对象，该对象包含实例集的 TLS 证书文件的位置（该证书文件存储在实例上）。从证书链中提取的根证书文件也存储在实例上。如果不成功，将返回错误消息。

有关证书和证书链数据的更多信息，请参阅 AWS Certificate Manager API 参考中的[GetCertificate 响应元素](https://docs.aws.amazon.com/acm/latest/APIReference/API_GetCertificate.html#API_GetCertificate_ResponseElements)。

### 示例
<a name="integration-server-sdk-cpp-ref-getinstancecertificate-example"></a>

```
Aws::GameLift::GetInstanceCertificateOutcome certificateOutcome = 
    Aws::GameLift::Server::GetInstanceCertificate();
```

## GetSdkVersion()
<a name="integration-server-sdk-cpp-ref-getsdk"></a>

返回正在使用中的软件开发工具包的当前版本号。

### 语法
<a name="integration-server-sdk-cpp-ref-getsdk-syntax"></a>

```
AwsStringOutcome GetSdkVersion();
```

### 参数
<a name="integration-server-sdk-cpp-ref-getsdk-parameter"></a>

此操作没有参数。

### 返回值
<a name="integration-server-sdk-cpp-ref-getsdk-return"></a>

如果成功，返回以 `AwsStringOutcome` 对象返回当前 SDK 的版本。返回的字符串仅包含版本号 (例如：如果不成功，将返回错误消息。

### 示例
<a name="integration-server-sdk-cpp-ref-getsdk-example"></a>

```
Aws::GameLift::AwsStringOutcome SdkVersionOutcome = 
    Aws::GameLift::Server::GetSdkVersion();
```

## GetTerminationTime()
<a name="integration-server-sdk-cpp-ref-getterm"></a>

如果终止时间可用，则返回安排服务器进程关闭的时间。服务器进程在收到来自 Amazon GameLift Servers 服务的 `onProcessTerminate()` 回调后执行此操作。Amazon GameLift Servers 可能出于以下原因调用 `onProcessTerminate()`：（1）服务器进程报告运行状况不佳或未响应 Amazon GameLift Servers，（2）在缩减事件期间终止实例，或（3）因[竞价型实例中断](spot-tasks.md)而导致实例终止。

如果该进程已收到 `onProcessTerminate()` 回调，则返回的值是估计的终止时间 (纪元秒)。如果进程未收到`onProcessTerminate()`回调，则会返回一条错误消息。了解有关[关闭服务器进程](gamelift-sdk-server-api.md#gamelift-sdk-server-terminate)的更多信息。

### 语法
<a name="integration-server-sdk-cpp-ref-getterm-syntax"></a>

```
AwsLongOutcome GetTerminationTime();
```

### 参数
<a name="integration-server-sdk-cpp-ref-getterm-parameter"></a>

此操作没有参数。

### 返回值
<a name="integration-server-sdk-cpp-ref-getterm-return"></a>

如果成功，则以`AwsLongOutcome`对象形式返回终止时间。该值是终止时间，以自 0001 00:00:00 起经过的报价表示。例如，日期时间值 2020-09-13 12:26:40-000Z 等于 637355968000000000 滴答作响。如果没有可用的终止时间，将返回一条错误消息。

### 示例
<a name="integration-server-sdk-cpp-ref-getterm-example"></a>

```
Aws::GameLift::AwsLongOutcome TermTimeOutcome = 
    Aws::GameLift::Server::GetTerminationTime();
```

## InitSDK()
<a name="integration-server-sdk-cpp-ref-initsdk"></a>

初始化 Amazon GameLift Servers 开发工具包。应在启动之后、进行任何其他 Amazon GameLift Servers 相关的初始化之前调用此方法。

### 语法
<a name="integration-server-sdk-cpp-ref-initsdk-syntax"></a>

```
InitSDKOutcome InitSDK();
```

### 参数
<a name="integration-server-sdk-cpp-ref-initsdk-parameter"></a>

此操作没有参数。

### 返回值
<a name="integration-server-sdk-cpp-ref-initsdk-return"></a>

如果成功，则返回一个 InitSdkOutcome 对象，表示服务器进程已准备好调用[ProcessReady()](#integration-server-sdk-cpp-ref-processready)。

### 示例
<a name="integration-server-sdk-cpp-ref-initsdk-example"></a>

```
Aws::GameLift::Server::InitSDKOutcome initOutcome = 
    Aws::GameLift::Server::InitSDK();
```

## ProcessEnding()
<a name="integration-server-sdk-cpp-ref-processending"></a>

通知 Amazon GameLift Servers 服务，该服务器进程正在关闭。应在所有其他清除任务 (包括关闭所有活动游戏会话) 之后调用此方法。此方法应退出，退出代码为 0；非零退出代码将导致生成一条事件消息，提示进程未完全退出。

当该方法以代码为 0 退出后，您可以使用成功的退出代码终止该进程。您也可以退出，并返回错误代码。如果您退出时出现错误代码，则队列事件将指示进程异常终止（`SERVER_PROCESS_TERMINATED_UNHEALTHY`）。

### 语法
<a name="integration-server-sdk-cpp-ref-processending-syntax"></a>

```
GenericOutcome ProcessEnding();
```

### 参数
<a name="integration-server-sdk-cpp-ref-processending-parameter"></a>

此操作没有参数。

### 返回值
<a name="integration-server-sdk-cpp-ref-processending-return"></a>

返回由成功或失败组成的通用结果，并显示错误消息。

### 示例
<a name="integration-server-sdk-cpp-ref-processending-example"></a>

```
Aws::GameLift::GenericOutcome outcome = Aws::GameLift::Server::ProcessEnding();
if (outcome.Success)
    exit(0);  // exit with success
// otherwise, exit with error code
exit(errorCode);
```

## ProcessReady()
<a name="integration-server-sdk-cpp-ref-processready"></a>

通知 Amazon GameLift Servers 服务，服务器进程已准备好托管游戏会话。在成功调用 [InitSDK()](#integration-server-sdk-cpp-ref-initsdk) 并完成了服务器进程托管游戏会话所需的全部设置任务后，应调用此方法。每个进程只能调用一次此方法。

此调用为同步操作。要进行异步调用，请使用 [ProcessReadyAsync()](#integration-server-sdk-cpp-ref-processreadyasync)。有关更多信息，请参阅[初始化服务器进程](gamelift-sdk-server-api.md#gamelift-sdk-server-initialize)。

### 语法
<a name="integration-server-sdk-cpp-ref-processready-syntax"></a>

```
GenericOutcome ProcessReady(
    const Aws::GameLift::Server::ProcessParameters &processParameters);
```

### 参数
<a name="integration-server-sdk-cpp-ref-processready-parameter"></a>

**processParameters**  
[ProcessParameters](integration-server-sdk-cpp-ref-datatypes.md#integration-server-sdk-cpp-ref-dataypes-process) 对象，用于传输有关服务器进程的以下信息：  
+ 游戏服务器代码中实现的回调方法的名称，Amazon GameLift Servers 服务调用其与服务器进程通信。
+ 服务器进程正在侦听的端口号。
+ 您希望 Amazon GameLift Servers 捕获和存储的任何游戏会话特定文件的路径。
是否必需：是

### 返回值
<a name="integration-server-sdk-cpp-ref-processready-return"></a>

返回由成功或失败组成的通用结果，并显示错误消息。

### 示例
<a name="integration-server-sdk-cpp-ref-processready-example"></a>

此示例演示了 [ProcessReady()](#integration-server-sdk-cpp-ref-processready) 调用和回调函数的实现。

```
// Set parameters and call ProcessReady
std::string serverLog("serverOut.log");        // Example of a log file written by the game server
std::vector<std::string> logPaths;
logPaths.push_back(serverLog);

int listenPort = 9339;

Aws::GameLift::Server::ProcessParameters processReadyParameter = Aws::GameLift::Server::ProcessParameters(
    std::bind(&Server::onStartGameSession, this, std::placeholders::_1),
    std::bind(&Server::onProcessTerminate, this),
    std::bind(&Server::OnHealthCheck, this),
    std::bind(&Server::OnUpdateGameSession, this),
    listenPort,
    Aws::GameLift::Server::LogParameters(logPaths)); 

Aws::GameLift::GenericOutcome outcome = 
   Aws::GameLift::Server::ProcessReady(processReadyParameter);

// Implement callback functions
void Server::onStartGameSession(Aws::GameLift::Model::GameSession myGameSession)
{
   // game-specific tasks when starting a new game session, such as loading map
   GenericOutcome outcome = 
       Aws::GameLift::Server::ActivateGameSession (maxPlayers);
}

void Server::onProcessTerminate()
{
   // game-specific tasks required to gracefully shut down a game session, 
   // such as notifying players, preserving game state data, and other cleanup
   GenericOutcome outcome = Aws::GameLift::Server::ProcessEnding();
}

bool Server::onHealthCheck()
{
    bool health;
    // complete health evaluation within 60 seconds and set health
    return health;
}
```

## ProcessReadyAsync()
<a name="integration-server-sdk-cpp-ref-processreadyasync"></a>

通知 Amazon GameLift Servers 服务，服务器进程已准备好托管游戏会话。在服务器进程准备好托管游戏会话后，应调用此方法。该方法的参数用于指定 Amazon GameLift Servers 在特定环境下应调用的回调函数的名称。游戏服务器代码必须执行这些函数。

此调用为异步操作。要进行同步调用，请使用 [ProcessReady()](#integration-server-sdk-cpp-ref-processready)。有关更多信息，请参阅[初始化服务器进程](gamelift-sdk-server-api.md#gamelift-sdk-server-initialize)。

### 语法
<a name="integration-server-sdk-cpp-ref-processreadyasync-syntax"></a>

```
GenericOutcomeCallable ProcessReadyAsync(
    const Aws::GameLift::Server::ProcessParameters &processParameters);
```

### 参数
<a name="integration-server-sdk-cpp-ref-processreadyasync-parameter"></a>

**processParameters**  
[ProcessParameters](integration-server-sdk-cpp-ref-datatypes.md#integration-server-sdk-cpp-ref-dataypes-process) 对象，用于传输有关服务器进程的以下信息：  
+ 游戏服务器代码中实现的回调方法的名称，Amazon GameLift Servers 服务调用其与服务器进程通信。
+ 服务器进程正在侦听的端口号。
+ 您希望 Amazon GameLift Servers 捕获和存储的任何游戏会话特定文件的路径。
是否必需：是

### 返回值
<a name="integration-server-sdk-cpp-ref-processreadyasync-return"></a>

返回由成功或失败组成的通用结果，并显示错误消息。

### 示例
<a name="integration-server-sdk-cpp-ref-processreadyasync-example"></a>

```
// Set parameters and call ProcessReady
std::string serverLog("serverOut.log");        // This is an example of a log file written by the game server
std::vector<std::string> logPaths;
logPaths.push_back(serverLog);

int listenPort = 9339;

Aws::GameLift::Server::ProcessParameters processReadyParameter = Aws::GameLift::Server::ProcessParameters(
    std::bind(&Server::onStartGameSession, this, std::placeholders::_1),
    std::bind(&Server::onProcessTerminate, this),
    std::bind(&Server::OnHealthCheck, this),
    std::bind(&Server::OnUpdateGameSession, this),
    listenPort,
    Aws::GameLift::Server::LogParameters(logPaths));

Aws::GameLift::GenericOutcomeCallable outcome = 
   Aws::GameLift::Server::ProcessReadyAsync(processReadyParameter);

// Implement callback functions
void onStartGameSession(Aws::GameLift::Model::GameSession myGameSession)
{
   // game-specific tasks when starting a new game session, such as loading map
   GenericOutcome outcome = Aws::GameLift::Server::ActivateGameSession (maxPlayers);
}

void onProcessTerminate()
{
   // game-specific tasks required to gracefully shut down a game session, 
   // such as notifying players, preserving game state data, and other cleanup
   GenericOutcome outcome = Aws::GameLift::Server::ProcessEnding();
}

bool onHealthCheck()
{
    // perform health evaluation and complete within 60 seconds
    return health;
}
```

## RemovePlayerSession()
<a name="integration-server-sdk-cpp-ref-removeplayersession"></a>

通知 Amazon GameLift Servers 服务，具有所指定玩家会话 ID 的玩家已从服务器进程断开连接。作为响应，Amazon GameLift Servers 将玩家位置更改为可用，这使得该玩家位置可以分配给新玩家。

### 语法
<a name="integration-server-sdk-cpp-ref-removeplayersession-syntax"></a>

```
GenericOutcome RemovePlayerSession(
    const std::string& playerSessionId);
```

### 参数
<a name="integration-server-sdk-cpp-ref-removeplayersession-parameter"></a>

**playerSessionId**  
Amazon GameLift Servers服务为响应 AWS SDK Amazon GameLift Servers API 操作调用而颁发的唯一 ID [CreatePlayerSession](https://docs.aws.amazon.com/gamelift/latest/apireference/API_CreatePlayerSession.html)。连接到服务器进程时，游戏客户端会引用此 ID。  
类型：std:: string  
是否必需：是

### 返回值
<a name="integration-server-sdk-cpp-ref-removeplayersession-return"></a>

返回由成功或失败组成的通用结果，并显示错误消息。

### 示例
<a name="integration-server-sdk-cpp-ref-removeplayersession-example"></a>

```
Aws::GameLift::GenericOutcome disconnectOutcome = 
    Aws::GameLift::Server::RemovePlayerSession(playerSessionId);
```

## StartMatchBackfill()
<a name="integration-server-sdk-cpp-ref-startmatchbackfill"></a>

发送请求以为使用 FlexMatch 创建的游戏会话中的开放位置查找新玩家。另请参阅 S AWS DK 操作 [StartMatchBackfill()](https://docs.aws.amazon.com/gamelift/latest/apireference/API_StartMatchBackfill.html)。通过此操作，托管游戏会话的游戏服务器进程可以发出匹配回填请求。了解有关 [FlexMatch 回填功能](https://docs.aws.amazon.com/gameliftservers/latest/flexmatchguide/match-backfill.html)的更多信息。

此操作为异步操作。如果成功匹配了新玩家，则 Amazon GameLift Servers 服务会通过调用回调函数 `OnUpdateGameSession()` 提供更新的对战构建器数据。

服务器进程每次只能具有一个活动的对战回填请求。要发送新请求，请先调用 [StopMatchBackfill()](#integration-server-sdk-cpp-ref-stopmatchbackfill) 以取消原始请求。

### 语法
<a name="integration-server-sdk-cpp-ref-startmatchbackfill-syntax"></a>

```
StartMatchBackfillOutcome StartMatchBackfill ( 
    const Aws::GameLift::Server::Model::StartMatchBackfillRequest &startBackfillRequest);
```

### 参数
<a name="integration-server-sdk-cpp-ref-startmatchbackfill-parameter"></a>

**StartMatchBackfillRequest**  
一个 [StartMatchBackfillRequest](integration-server-sdk-cpp-ref-datatypes.md#integration-server-sdk-cpp-ref-dataypes-startmatchbackfillrequest) 对象，用于传递以下信息：  
+ 要分配给回填请求的票证 ID。此信息是可选的；如果未提供任何 ID，则 Amazon GameLift Servers 将自动生成一个 ID。
+ 要将请求发送到的对战构建器。需要完整的配置 ARN。可从游戏会话的对战构建器数据中获得此值。
+ 正在进行回填的游戏会话的 ID。
+ 游戏会话的当前玩家的可用对战数据。
是否必需：是

### 返回值
<a name="integration-server-sdk-cpp-ref-startmatchbackfill-return"></a>

返回带有匹配回填票证或失败并显示错误消息的 StartMatchBackfillOutcome 对象。可以使用 AWS SDK 操作 [DescribeMatchmaking()](https://docs.aws.amazon.com/gamelift/latest/apireference/API_DescribeMatchmaking.html) 跟踪票证状态。

### 示例
<a name="integration-server-sdk-cpp-ref-startmatchbackfill-example"></a>

```
// Build a backfill request
std::vector<Player> players;
Aws::GameLift::Server::Model::StartMatchBackfillRequest startBackfillRequest;
startBackfillRequest.SetTicketId("a ticket ID");                                         //optional, autogenerated if not provided
startBackfillRequest.SetMatchmakingConfigurationArn("the matchmaker configuration ARN"); //from the game session matchmaker data
startBackfillRequest.SetGameSessionArn("the game session ARN");                          // can use GetGameSessionId()
startBackfillRequest.SetPlayers(players);                                                  //from the game session matchmaker data

// Send backfill request
Aws::GameLift::StartMatchBackfillOutcome backfillOutcome = 
    Aws::GameLift::Server::StartMatchBackfill(startBackfillRequest);

// Implement callback function for backfill
void Server::OnUpdateGameSession(Aws::GameLift::Server::Model::GameSession gameSession, Aws::GameLift::Server::Model::UpdateReason updateReason, std::string backfillTicketId)
{
   // handle status messages
   // perform game-specific tasks to prep for newly matched players
}
```

## StopMatchBackfill()
<a name="integration-server-sdk-cpp-ref-stopmatchbackfill"></a>

取消使用 [StartMatchBackfill()](#integration-server-sdk-cpp-ref-startmatchbackfill) 创建的活动对战回填请求。另请参阅 S AWS DK 操作 [StopMatchmaking()](https://docs.aws.amazon.com/gamelift/latest/apireference/API_StopMatchmaking.html)。了解有关 [FlexMatch 回填功能](https://docs.aws.amazon.com/gameliftservers/latest/flexmatchguide/match-backfill.html)的更多信息。

### 语法
<a name="integration-server-sdk-cpp-ref-stopmatchbackfill-syntax"></a>

```
GenericOutcome StopMatchBackfill ( 
    const Aws::GameLift::Server::Model::StopMatchBackfillRequest &stopBackfillRequest);
```

### 参数
<a name="integration-server-sdk-cpp-ref-stopmatchbackfill-parameter"></a>

**StopMatchBackfillRequest**  
一个 [StopMatchBackfillRequest](integration-server-sdk-cpp-ref-datatypes.md#integration-server-sdk-cpp-ref-dataypes-stopmatchbackfillrequest) 对象，用于识别要取消的对战票证：  
+ 分配给被取消的回填请求的票证 ID
+ 回填请求所发送到的对战构建器
+ 与回填请求关联的游戏会话
是否必需：是

### 返回值
<a name="integration-server-sdk-cpp-ref-stopmatchbackfill-return"></a>

返回由成功或失败组成的通用结果，并显示错误消息。

### 示例
<a name="integration-server-sdk-cpp-ref-stopmatchbackfill-example"></a>

```
// Set backfill stop request parameters

Aws::GameLift::Server::Model::StopMatchBackfillRequest stopBackfillRequest;
stopBackfillRequest.SetTicketId("the ticket ID");
stopBackfillRequest.SetGameSessionArn("the game session ARN");                           // can use GetGameSessionId()
stopBackfillRequest.SetMatchmakingConfigurationArn("the matchmaker configuration ARN");  // from the game session matchmaker data

Aws::GameLift::GenericOutcome stopBackfillOutcome = 
    Aws::GameLift::Server::StopMatchBackfillRequest(stopBackfillRequest);
```

## TerminateGameSession()
<a name="integration-server-sdk-cpp-ref-terminategamesession"></a>

**此方法在版本 4.0.1 中已弃用。相反，服务器进程应在游戏会话结束[ProcessEnding()](#integration-server-sdk-cpp-ref-processending)后调用。**

通知 Amazon GameLift Servers 服务，服务器进程已结束当前游戏会话。当服务器进程保持活动状态并准备托管新游戏会话时，将调用此操作。只有在游戏会话终止程序完成后才应调用此操作，因为它会向 Amazon GameLift Servers 发出信号，表明服务器进程可以立即用于托管新的游戏会话。

如果服务器进程将在游戏会话停止后关闭，则不会调用此操作。取而代之的是，调用[ProcessEnding()](#integration-server-sdk-cpp-ref-processending)表示游戏会话和服务器进程都将结束。

### 语法
<a name="integration-server-sdk-cpp-ref-terminategamesession-syntax"></a>

```
GenericOutcome TerminateGameSession();
```

### 参数
<a name="integration-server-sdk-cpp-ref-terminategamesession-parameter"></a>

此操作没有参数。

### 返回值
<a name="integration-server-sdk-cpp-ref-terminategamesession-return"></a>

返回由成功或失败组成的通用结果，并显示错误消息。

## UpdatePlayerSessionCreationPolicy()
<a name="integration-server-sdk-cpp-ref-updateplayersessioncreationpolicy"></a>

更新当前游戏会话接受新玩家会话的能力。可将游戏会话设置为接受或拒绝所有新的玩家会话。另请参阅 S AWS DK 操作 [UpdateGameSession()](https://docs.aws.amazon.com/gamelift/latest/apireference/API_UpdateGameSession.html)。

### 语法
<a name="integration-server-sdk-cpp-ref-updateplayersessioncreationpolicy-syntax"></a>

```
GenericOutcome UpdatePlayerSessionCreationPolicy(
    Aws::GameLift::Model::PlayerSessionCreationPolicy newPlayerSessionPolicy);
```

### 参数
<a name="integration-server-sdk-cpp-ref-updateplayersessioncreationpolicy-parameter"></a>

**newPlayerSession政策**  
用于指示游戏会话是否接受新玩家的字符串值。  
类型：Aws:::GameLift: Model:: PlayerSessionCreationPolicy enum。有效值包括：  
+ **ACCEPT\$1ALL** - 接受所有新玩家会话。
+ **DENY\$1ALL** - 拒绝所有新玩家会话。
是否必需：是

### 返回值
<a name="integration-server-sdk-cpp-ref-updateplayersessioncreationpolicy-return"></a>

返回由成功或失败组成的通用结果，并显示错误消息。

### 示例
<a name="integration-server-sdk-cpp-ref-updateplayersessioncreationpolicy-example"></a>

此示例将当前游戏会话的接入策略设为接受所有玩家。

```
Aws::GameLift::GenericOutcome outcome = Aws::GameLift::Server::UpdatePlayerSessionCreationPolicy(Aws::GameLift::Model::PlayerSessionCreationPolicy::ACCEPT_ALL);
```

## Destroy
<a name="integration-server-sdk-cpp-ref-destroy"></a>

在游戏服务器初始化期间清理 initSDK () 分配的内存。在结束游戏服务器进程后使用此方法，以避免浪费服务器内存。

### 语法
<a name="integration-server-sdk-cpp-ref-destroy-syntax"></a>

```
GenericOutcome Aws::GameLift::Server::Destroy();
```

### 参数
<a name="integration-server-sdk-cpp-ref-destroy-parameter"></a>

没有参数。

### 返回值
<a name="integration-server-sdk-cpp-ref-destroy-return"></a>

返回由成功或失败组成的通用结果，并显示错误消息。

### 示例
<a name="integration-server-sdk-cpp-ref-destroy-example"></a>

此示例在游戏服务器进程结束后清理 InitSDK 分配的内存。

```
if (Aws::GameLift::Server::ProcessEnding().IsSuccess()) {
  Aws::GameLift::Server::Destroy();
  exit(0);
}
```