マッチメイキングからセッションを記録および除外する
注釈:本資料はAI技術を用いて翻訳されています。
この記事では、Unreal Engineゲームプロジェクトでのセッション除外の処理について説明します。Unityを使用している場合は、マッチメイキングの統合(Unity)ガイドを参照してください。
概要
AccelByte Gaming Services(AGS)は、プレイヤーが同じセッションに繰り返しマッチングされるのを防ぐ機能を提供します。AGSマッチメイキングサービスでは、マッチメイキング結果から特定のセッションを除外でき、AGS Unreal Engine OSSを使用してプレイヤーセッション履歴を記録できます。この組み合わせ機能により、ゲームは以前に参加したセッションにプレイヤーをマッチングしないようにすることができます。
この記事では、ゲームで次の機能を有効にする方法を説明します:
- プレイヤーがセッション履歴を記録できるようにする
- プレイヤーセッション履歴を取得、変更、リセットする
- プレイヤーとパーティリーダーがマッチメイキング結果からセッションを除外できるようにする
セッション履歴を記録する
ゲーム内のプレイヤーがセッション履歴(ゲームを起動してからのセッション)を記録できるようにするには、SetEnablePartyMemberPastSessionRecordSync関数を追加します:
void ExampleLoginManagerClass::OnUserLoginSuccess()
{
uint32 PastGameSessionIdRecordCount = 20; // メモリに記録される過去のゲームセッションIDの量、数値は例です。
SessionInterface->SetEnablePartyMemberPastSessionRecordSync(true, PastGameSessionIdRecordCount);
}
有効にすると、ゲームが起動された瞬間からプレイヤーのセッション履歴をデバイスにローカルで自動的に記録します。セッション記録は、ゲームが閉じられるとクリアされます。プレイヤーは、好みに応じていつでもこの機能を有効または無効にできます。
- ゲームが起動され、オンラインサブシステム(OSS)がロードされた後にこの関数を呼び出します。上記のサンプルコードはこれを確立しています。
- この関数は個々のプレイヤーレベルで動作します。この機能を無効にしているプレイヤーがパーティのメンバーである場合、他のメンバーが有効にしていても、セッション履歴はパーティと同期されません。
- 上記のコードは、プレイヤーの最後の20セッションが記録されることを指定しています。記録する過去のセッションの希望数に合わせて
PastGameSessionIdRecordCount値を調整できます。値が大きいほど、ペイロードが大きくなることに注意してください。
マッチメイキングからセッションを除外する
プレイヤーとパーティリーダーに、マッチメイキング結果から過去および特定のセッションを除外するオプションを提供できます。マッチメイキングサービスは、個々のプレイヤーとパーティレベルの両方で適用可能な次の除外タイプをサポートしています:
- タイプ1:特定のセッションを除外
FAccelByteModelsGameSessionExcludedSession::CreateExclusionList(TSet<FString> SetOfExcludedGameSessionId); - タイプ2:すべての過去のセッションを除外
FAccelByteModelsGameSessionExcludedSession::CreateExclusionEntireSessionMemberPastSession(); - タイプ3:特定の数の最新セッションを除外
FAccelByteModelsGameSessionExcludedSession::CreateExclusionCount(ExcludedPastSessionCount); - タイプ4:除外なし
FAccelByteModelsGameSessionExcludedSession::CreateNoExclusion();
タイプ2および3の除外方法の場合、プレイヤーはセッションを除外するためにセッション履歴記録を有効にする必要があります。機能を有効にする方法については、セッション履歴を記録するセクションを参照してください。
個々のプレイヤー向け
個々のプレイヤーに対して次の除外方法を有効にできます:
特定のゲームセッションを除外する
プレイヤーが特定のゲームセッションに参加しないようにするには、このコードで除外されるセッションのIDを指定します:
TSet<FString> ListOfExcludedSession{};
ListOfExcludedSession.Add("GAMESESSION_ID_AAA"); // 回避されるセッションの例
ListOfExcludedSession.Add("GAMESESSION_ID_BBB"); // 回避されるセッションの例
ListOfExcludedSession.Add("GAMESESSION_ID_CCC"); // 回避されるセッションの例
MatchmakingSearchHandle->GameSessionExclusion = FAccelByteModelsGameSessionExcludedSession::CreateExclusionList(ListOfExcludedSession);
SessionInterface->StartMatchmaking(USER_ID_TO_MATCHMAKING_USER_ARRAY(LocalPlayerId.ToSharedRef()), NAME_GameSession, FOnlineSessionSettings(), MatchmakingSearchHandle, OnStartMatchmakingCompleteDelegate);
すべての過去のセッションを除外する
この機能は、セッション履歴記録を有効にしているプレイヤーにのみ適用されます。除外するセッションを決定するためにセッション履歴に依存しているためです。セッション履歴記録機能がゲームに統合されていることを確認してください。詳細については、セッション履歴を記録するセクションを参照してください。
ゲームを起動してからのすべての過去のセッションにプレイヤーが参加しないようにするには、このコードを使用します:
// On User Login Success
SessionInterface->SetEnablePartyMemberPastSessionRecordSync(true, 20);
...
MatchmakingSearchHandle->GameSessionExclusion = FAccelByteModelsGameSessionExcludedSession::CreateExclusionEntireSessionMemberPastSession();
SessionInterface->StartMatchmaking(USER_ID_TO_MATCHMAKING_USER_ARRAY(LocalPlayerId.ToSharedRef()), NAME_GameSession, FOnlineSessionSettings(), MatchmakingSearchHandle, OnStartMatchmakingCompleteDelegate);
特定の数の最新セッションを除外する
この機能は、セッション履歴記録を有効にしているプレイヤーにのみ適用されます。除外するセッションを決定するためにセッション履歴に依存しているためです。セッション履歴記録機能がゲームに統合されていることを確認してください。詳細については、セッション履歴を記録するセクションを参照してください。
プレイヤーが特定の数の最新セッションに参加しないようにするには、以下のコードスニペットを使用します。ExcludedPastSessionCountパラメータを使用して除外するセッションの数を指定します。たとえば、次のコードは、プレイヤーの最後の5つのセッションをマッチメイキング結果から除外します。
// On User Login Success
SessionInterface->SetEnablePartyMemberPastSessionRecordSync(true, 20);
...
const uint32 ExcludedPastSessionCount = 5;
MatchmakingSearchHandle->GameSessionExclusion = FAccelByteModelsGameSessionExcludedSession::CreateExclusionCount(ExcludedPastSessionCount);
SessionInterface->StartMatchmaking(USER_ID_TO_MATCHMAKING_USER_ARRAY(LocalPlayerId.ToSharedRef()), NAME_GameSession, FOnlineSessionSettings(), MatchmakingSearchHandle, OnStartMatchmakingCompleteDelegate);
パーティリーダー向け
パーティリーダーによって適用される除外は、セッション履歴記録を有効にしているメンバーの記録に基づいて行われます。除外方法は、除外するセッションを決定するためにこれらの履歴に依存しているためです。セッション履歴記録機能がゲームに統合されていることを確認してください。詳細については、セッション履歴を記録するセクションを参照してください。
パーティリーダーに対して次の除外方法を有効にできます:
特定のゲームセッションを除外する
メンバーが特定のゲームセッションに参加しないようにするには、このコードで除外されるセッションのIDを指定します:
TSet<FString> ListOfExcludedSession{};
ListOfExcludedSession.Add("GAMESESSION_ID_AAA"); // Example of avoided session
ListOfExcludedSession.Add("GAMESESSION_ID_BBB"); // Example of avoided session
ListOfExcludedSession.Add("GAMESESSION_ID_CCC"); // Example of avoided session
MatchmakingSearchHandle->GameSessionExclusion = FAccelByteModelsGameSessionExcludedSession::CreateExclusionList(ListOfExcludedSession);
SessionInterface->StartMatchmaking(USER_ID_TO_MATCHMAKING_USER_ARRAY(LocalPlayerId.ToSharedRef()), NAME_GameSession, FOnlineSessionSettings(), MatchmakingSearchHandle, OnStartMatchmakingCompleteDelegate);
すべてのメンバーの過去のセッションを除外する
パーティリーダーがマッチメイキング結果からすべてのメンバーの過去のセッションを除外できるようにするには、この関数を追加します:
// On successful player login
/*Leader game client*/SessionInterface->SetEnablePartyMemberPastSessionRecordSync(true, PastSessionCount);
/*Member1 game client*/SessionInterface->SetEnablePartyMemberPastSessionRecordSync(true, PastSessionCount);
/*Member2 game client*/SessionInterface->SetEnablePartyMemberPastSessionRecordSync(true, PastSessionCount);
...
// The main toggle for the party leader to enable this feature
// Example if the leader wants to only exclude the five MOST RECENT SESSION from each party member's record
const uint32 ExcludedPastSessionCount = 5;
MatchmakingSearchHandle->GameSessionExclusion = FAccelByteModelsGameSessionExcludedSession::CreateExclusionCount(ExcludedPastSessionCount);
SessionInterface->StartMatchmaking(USER_ID_TO_MATCHMAKING_USER_ARRAY(LocalPlayerId.ToSharedRef()), NAME_GameSession, FOnlineSessionSettings(), MatchmakingSearchHandle, OnStartMatchmakingCompleteDelegate);
メンバーの特定の数の最新セッションを除外する
パーティリーダーがメンバーの特定の数の最新セッションを除外できるようにするには、この関数を追加します:
// On User Login Success
/*Leader game client*/SessionInterface->SetEnablePartyMemberPastSessionRecordSync(true, PastSessionCount);
/*Member1 game client*/SessionInterface->SetEnablePartyMemberPastSessionRecordSync(true, PastSessionCount);
/*Member2 game client*/SessionInterface->SetEnablePartyMemberPastSessionRecordSync(true, PastSessionCount);
...
// The main toggle for the party leader to enable this feature
// Example if the leader wants to only include the five MOST RECENT SESSION from each party member's record
const uint32 ExcludedPastSessionCount = 5;
MatchmakingSearchHandle->GameSessionExclusion = FAccelByteModelsGameSessionExcludedSession::CreateExclusionCount(ExcludedPastSessionCount);
SessionInterface->StartMatchmaking(USER_ID_TO_MATCHMAKING_USER_ARRAY(LocalPlayerId.ToSharedRef()), NAME_GameSession, FOnlineSessionSettings(), MatchmakingSearchHandle, OnStartMatchmakingCompleteDelegate);
パーティリーダーがメンバーのセッション履歴を取得および変更できるようにする
AGSマッチメイキングサービスは、パーティリーダーが過去のセッションの一般的な除外を上書きできるように設定できます。パーティリーダーは、メンバーのセッション履歴を確認し、記録から削除することで特定のセッションをホワイトリストに登録できます。
これを有効にするには、次のコードを実装します:
// Obtain the storage, asynchronously
SessionInterface->GetPartySessionStorage(AccelByteUserUniqueNetId,
FOnGetPartySessionStorageComplete::CreateLambda([&]
(const FAccelByteModelsV2PartySessionStorage& Result, bool bWasSuccessful) {
bGetSessionStorageDone = true;
bGetSessionStorageSuccess = bWasSuccessful;
PartySessionStorageResult = Result;
}));
// Wait for response
WaitUntil(bGetSessionStorageDone);
// Check the content, iterate as we wish.
Map<FString /*UserID*/, FAccelByteModelsV2PartySessionStorageReservedData> MapOfPartyMemberStorage = PartySessionStorageResult.Reserved;
プレイヤーセッション履歴を取得、変更、リセットする
セッション履歴はプレイヤーのデバイスにローカルに保存されているため、直接変更することはできません。ただし、セッション履歴を管理するクラスを使用して、プレイヤーのローカル記録を挿入、取得、またはリセットできます。更新後、必要に応じてこれらの変更を同期できます。
次の関数を使用します:
// INSERT MANUALLY
SessionInterface->PartySessionStorageLocalUserManager.PastSessionManager.InsertPastSessionID(UniqueNetIdRefs, "DummySession1");
// RESET ENTIRE ENTRY
SessionInterface->PartySessionStorageLocalUserManager.PastSessionManager.ResetCachedPastSessionIDs(UniqueNetIdRefs);
// GET CURRENT PLAYER's ENTRY
SessionInterface->PartySessionStorageLocalUserManager.PastSessionManager.GetPastSessionIDs(UniqueNetIdRefs);
プレイヤーの記録に変更を適用し、プレイヤーのパーティと同期するには(該当する場合)、次の関数を使用します:
// Result listener
ForceUpdateHandle = SessionInterface->AddOnUpdatePlayerReservedPartySessionStorageCompleteDelegate_Handle(
FOnUpdatePlayerReservedPartySessionStorageCompleteDelegate::CreateLambda([&](const FAccelByteModelsV2PartySessionStorageReservedData& Result, bool bWasSuccessful, const FOnlineError& ErrorInfo)
{
bForceUpdateDone = true;
SessionInterface->ClearOnUpdatePlayerReservedPartySessionStorageCompleteDelegate_Handle(ForceUpdateHandle);
bForceUpdateSuccess = bWasSuccessful;
ForceUpdateResult = Result;
}));
....
// Do the modification similar to the example INSERT/RESET/GET
SessionInterface->PartySessionStorageLocalUserManager.PastSessionManager.......
// Send the update to the party
bool bRequestOkToUpdatePartyStorage = SessionInterface->UpdatePartySessionStorageWithPastSessionInfo(
FUniqueNetIdAccelByteUser::Create(UniqueNetIdRefs.Get()));
...
// Wait until (bForceUpdateDone == true)