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に接続する方法を示します。
- Unreal OSS
- Unity
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 ..."));
string serverId = "ds_65a24d80-0fc2-413c-b87c-1429f08edc4e";
var dsHubClient = AccelByteSDK.GetServerRegistry().GetApi().GetDsHub();
dsHubWrapper.OnConnected += () =>
{
//Do Something when this is connected
};
dsHubWrapper.Connect(serverId);
通知をリッスンする
DS HubはAGSサービスからさまざまな通知を受信できます。以下は、それらをリッスンする方法です:
- Unity
- C++
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}");
}
};
// Listen for specific notification types
dshubClient->SetNotificationCallback([](const std::string& topic, const std::string& payload) {
if (topic == "DSHUB_CONNECTED") {
// Handle dshub connected
break
} else if (topic == "serverClaimed") {
// Handle server claimed notif
HandleServerClaimed(payload);
} else if (topic == "BACKFILL_PROPOSAL") {
// Handle matchmaking backfill proposal
HandleBackfillProposal(payload);
} else if (topic == "SESSION_MEMBER_CHANGED") {
// Handle session member changes
HandleSessionMemberChanged(payload);
}
});
カスタム通知を送信する
DS Hubを通じて他のサービスにカスタム通知を送信できます:
- C++
// 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が一般的に受信する通知は以下の通りです(ペイロードの詳細については通知をクリックしてください):
- BACKFILL_PROPOSAL — マッチメイキングバックフィル提案。実装ガイドライン:AGS OSSでのバックフィルチケットの管理。ペイロードの詳細を参照:サーバー通知 — BACKFILL_PROPOSAL
- BACKFILL_TICKET_EXPIRE — バックフィルチケットの期限切れ。ペイロードの詳細を参照:サーバー通知 — BACKFILL_TICKET_EXPIRE
- serverClaimed — セッションに割り当て/クレームされたサーバー。参照:サーバー通知 — serverClaimed
- SESSION_MEMBER_CHANGED — セッションメンバーシップの更新。参照:サーバー通知 — SESSION_MEMBER_CHANGED
- SESSION_ENDED_NOTIF — セッション終了通知。参照:サーバー通知 — SESSION_ENDED_NOTIF
- SESSION_SERVER_SECRET — セッションシークレット情報。参照:サーバー通知 — SESSION_SERVER_SECRET
- DSHUB_CONNECTED / DSHUB_DISCONNECTED — DS Hub接続ライフサイクルイベント(接続/切断)
- AGSからのその他のセッション/パーティー/ロビー通知(完全なリストは以下を参照)
完全なペイロード例とサーバー通知の完全なリストについては、以下を参照してください:サーバー通知
ベストプラクティス
-
接続管理
- 指数バックオフを使用した再接続ロジックを実装する
- 接続タイムアウトを適切に処理する
- デバッグのために接続イベントをログに記録する
- 再接続戦略を参照:WebSocket再接続戦略
-
通知処理
- 通知を非同期で処理する
- 処理前に通知ペイロードを検証する
- 不正な形式のメッセージに対するエラー処理を実装する
- ByteWarsゲームの実装例を参照
-
セキュリティ
- 認証情報を安全に保存する
- 初期接続にはHTTPSを使用する
- サーバー証明書を検証する
一般的な問題と解決策
-
接続の失敗
- DS HubのURLと認証情報を確認する
- ネットワーク接続を確認する
- 適切なファイアウォール設定を確認する
-
メッセージ処理
- 適切な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\"}"
}'