メインコンテンツまでスキップ

SDKを使用したDS Hubの設定

Last updated on February 4, 2026

注釈:本資料はAI技術を用いて翻訳されています。

概要

AccelByte Gaming Services(AGS)DS Hubは、WebSocketプロトコルを使用して、ゲームサーバーとバックエンドサービス間の継続的な接続を提供します。WebSocketは、サーバーとバックエンド間の双方向通信を可能にすることで、信頼性の高いリアルタイムデータ転送を保証します。

この記事では、AGS Game SDKを使用したDS Hubの設定について説明します。

目標

この記事の目標は、AGS Game SDKを使用して以下の方法を示すことです:

  • AGS DS Hubに接続する
  • 接続および切断イベントを処理する
  • 通知をリッスンする

前提条件

この記事の手順を完了するには、以下が必要です:

  • AGS管理ポータルへのアクセス
  • ゲームサーバーにインストールされたAGS Game SDK
  • DS Hub認証情報(ゲームサーバーのデプロイ時に取得)

DS Hubに接続する

このセクションでは、ゲームサーバーをDS Hubに接続する方法を示します。

FOnlineSubsystemAccelByte* AccelByteSubsystemPtr = static_cast<FOnlineSubsystemAccelByte*>(IOnlineSubsystem::Get(ACCELBYTE_SUBSYSTEM));

if (AccelByteSubsystemPtr == nullptr)
{
return;
}

const FOnlineSessionV2AccelBytePtr SessionInterface = StaticCastSharedPtr<FOnlineSessionV2AccelByte>(AccelByteSubsystemPtr->GetSessionInterface());

if (SessionInterface == nullptr)
{
return;
}

const FOnRegisterServerComplete OnRegisterServerComplete =
FOnRegisterServerComplete::CreateLambda([&](bool bWasSuccessful) {
bRegisterSuccess = bWasSuccessful;
bRegisterServerDone = true;
});

SessionInterface->RegisterServer(NAME_GameSession, OnRegisterServerComplete);
WaitUntil(bRegisterServerDone, TEXT("Wait until register server success ..."));

通知をリッスンする

DS HubはAGSサービスからさまざまな通知を受信できます。以下は、それらをリッスンする方法です:


var dshubClient = AccelByteSDK.GetServerRegistry().GetApi(notifications.ApiId).GetDsHub();

// listen AMS server claimed notif, Game Server can perform any action needed to AGS Services
dshubClient.MatchmakingV2ServerClaimed += (result) =>
{
if (result.IsError)
{
Debug.LogWarning($"Failed to claim DS. Error: {result.Error.Message}");
}
else
{
Debug.Log($"Success to claim DS: {result.Value}");
}
};

// listen Matchmaking v2 backfill proposal, Game Server can accept / reject the proposal
dshubClient.MatchmakingV2BackfillProposalReceived += (result) =>
{
if (result.IsError)
{
Debug.LogWarning($"Failed to receive backfill proposal. Error: {result.Error.Message}");
}
else
{
Debug.Log($"Success to receive backfill proposal: {result.Value}");
}
};

// listen Game Session Ended notification, Game Server can perform any action needed to AGS Services
dshubClient.GameSessionV2Ended += (result) => {
if (result.IsError)
{
Debug.LogWarning($"Failed to receive game session ended notification. Error: {result.Error.Message}");
}
else
{
Debug.Log($"Success to game session ended notification: {result.Value}");
}
};

// listen Game Session Member changed notification, Game Server can perform any action needed to AGS Services
dshubClient.GameSessionV2MemberChanged += (result) => {
if (result.IsError)
{
Debug.LogWarning($"Failed to receive game session ended notification. Error: {result.Error.Message}");
}
else
{
Debug.Log($"Success to receive game session member changed notification: {result.Value}");
}
};

カスタム通知を送信する

DS Hubを通じて他のサービスにカスタム通知を送信できます:

// Send a custom notification
std::string topic = "GAME_STATUS";
std::string payload = R"({"status": "MATCH_STARTED"})";

dshubClient->SendNotification(topic, payload, [](const bool success) {
if (success) {
LOG("Custom notification sent successfully");
} else {
LOG("Failed to send custom notification");
}
});

通知をリッスンする

DS HubはAGSサービスからさまざまな通知を受信できます。DS Hubが一般的に受信する通知は以下の通りです(ペイロードの詳細については通知をクリックしてください):

完全なペイロード例とサーバー通知の完全なリストについては、以下を参照してください:サーバー通知

ベストプラクティス

  1. 接続管理

    • 指数バックオフを使用した再接続ロジックを実装する
    • 接続タイムアウトを適切に処理する
    • デバッグのために接続イベントをログに記録する
    • 再接続戦略を参照:WebSocket再接続戦略
  2. 通知処理

    • 通知を非同期で処理する
    • 処理前に通知ペイロードを検証する
    • 不正な形式のメッセージに対するエラー処理を実装する
    • ByteWarsゲームの実装例を参照
  3. セキュリティ

    • 認証情報を安全に保存する
    • 初期接続にはHTTPSを使用する
    • サーバー証明書を検証する

一般的な問題と解決策

  1. 接続の失敗

    • DS HubのURLと認証情報を確認する
    • ネットワーク接続を確認する
    • 適切なファイアウォール設定を確認する
  2. メッセージ処理

    • 適切なJSON解析エラー処理を実装する
    • 予期しないメッセージ形式を適切に処理する
    • デバッグのために問題のあるメッセージをログに記録する

サーバーに通知を送信する

管理者またはサービスは、このエンドポイントを使用してサーバーにカスタム通知を送信できます。

レスポンスコード

エンドポイントは以下のHTTPステータスコードを返します:

  • 200 - 成功。通知がサーバーに正常に送信されました。
  • 404 - 見つかりません。これは以下の場合に発生します:
    • 指定されたサーバー(serverId/DS ID/サーバー名)が見つからない
    • サーバーがDS Hubに接続されていない
    • 無効なサーバーIDが提供された

リクエスト例


curl -X POST \
https://{domain}/dshub/v1/admin/namespaces/{namespace}/servers/{serverId}/notify \
-H 'Authorization: Bearer {token}' \
-H 'Content-Type: application/json' \
-d '{
"topic": "CUSTOM_NOTIFICATION",
"payload": "{\"message\": \"test notification\"}"
}'