> ## 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 Services SDK で PFAuthenticationGetEntityWithSecretKeyAsync を使用してタイトル エンティティとして認証し、Win32 でサーバー専用 API を呼び出します。

# タイトル エンティティを使用した PlayFab へのアクセス

プレイヤーとしてログインして PlayFab 呼び出しを行うのと同様に、タイトル エンティティとして認証し、そのエンティティを介して PlayFab 呼び出しを行うこともできます。タイトル エンティティは、プレイヤー エンティティでは利用できない特定の関数を使用できます。これらの関数の多くは "server" という単語が接頭辞として付いており、その一例が ServerAddPlayerTag です。

タイトル エンティティ ハンドルを取得する初期化手順は、プレイヤーとしてログインする場合と同じです。詳細については、[Win32 のクイックスタート](/services/playfab/sdks/c/quickstart-win32) 記事の「初期化」セクションを参照してください。

注意: 現時点では、サーバー関数は SDK の Win32 バージョンでのみ利用可能です。

## タイトル エンティティの認証

最初のステップで **PFServiceConfigHandle** を作成した後、[**PFAuthenticationGetEntityWithSecretKeyAsync**](/services/playfab/api-references/c/pfauthentication/functions/pfauthenticationgetentitywithsecretkeyasync) を呼び出してタイトル エンティティ ハンドルを取得できます。get entity 呼び出しが正常に完了すると、**PFEntityHandle** とともに **S\_OK** が返されます。このプロセスはプレイヤーとしてログインする場合と似ています。**PFEntityHandle** の戻り値の型は同じですが、この場合、エンティティ ハンドルはプレイヤー エンティティではなくタイトル エンティティを表します。このエンティティをゲーム サーバーと呼ぶことができます。

```cpp theme={null}
    PFAuthenticationGetEntityRequest request{};
    XAsyncBlock async{};

    // Add your own error handling when FAILED(hr) == true
    HRESULT hr = PFAuthenticationGetEntityWithSecretKeyAsync(
        serviceConfigHandle,
        secretKey, // title specific secret key
        &request,
        &async
    );

    hr = XAsyncGetStatus(&async, true); // This is doing a blocking wait for completion, but you can use the XAsyncBlock to set a callback instead for async style usage

    PFEntityHandle entityHandle;
    hr = PFAuthenticationGetEntityWithSecretKeyGetResult(
        &async,
        &entityHandle
    );
```

## サービス呼び出し

ゲーム サーバーが作成されたら、PlayFab バックエンドへの呼び出しを行うことができます。以下は、タイトル内の特定のプレイヤーにプレイヤー タグを追加する例です。

```cpp theme={null}
    XAsyncBlock async{};
    PFSegmentsAddPlayerTagRequest request{};
    addSegmentRequest.PlayFabId = "ABCDEF123456";
    addSegmentRequest.tagName = "tagName";
    HRESULT hr = PFSegmentsServerAddPlayerTagAsync(entityHandle, &request, &async);
    hr = XAsyncGetStatus(&async, true);
```

AddPlayerTag の例のように、ゲーム サーバーで使用される関数の多くは、プレイヤー データの取得または変更を伴います。この関数を使用するには、特定のプレイヤーの PlayFab ID が必要です。接続されたクライアントが PlayFab ID を提供することも、GetPlayFabIDsFromXboxLiveIDs のような呼び出しを介してサーバーが PlayFab から直接取得することもできます。

## リファレンス

[API リファレンス ドキュメント](/services/playfab/api-references/c/pfauthentication/pfauthentication_members)


## Related topics

- [エンティティ グループ](/ja-jp/services/playfab/community/associations/groups/quickstart.md)
- [エンティティ ファイル](/ja-jp/services/playfab/live-service-management/game-configuration/entities/entity-files.md)
- [利用可能な組み込みエンティティ タイプ](/ja-jp/services/playfab/live-service-management/game-configuration/entities/available-built-in-entity-types.md)
- [Game Server Configuration の概要](/ja-jp/services/playfab/live-service-management/game-configuration/index.md)
- [エンティティ クイックスタート](/ja-jp/services/playfab/live-service-management/game-configuration/entities/quickstart.md)
