Skip to main content

Joinable Sessions

Last updated on

Start Matchmaking for a Joinable Session

The following function is used to start matchmaking for a joinable session.

// make sure lobby is connected first and in a party.

// this flow is for when matched to a new session
FRegistry::Lobby.SetMatchmakingNotifDelegate(THandler<FAccelByteModelsMatchmakingNotice>::CreateLambda([&lobby](const FAccelByteModelsMatchmakingNotice& Result)
{
// matchmaking is completed when it's notif status is done, then send ready consent.
if(Result.Status == EAccelByteMatchmakingStatus::Done)
FRegistry::Lobby.SendReadyConsentRequest(Result.MatchId);
}));

// When matched to a new session, Lobby will give DS notification after all matched player give ready consent.
// when matched to an existing session, lobby will directly give DS Notification, no ready consent required.
FRegistry::Lobby.SetDsNotifDelegate(THandler<FAccelByteModelsDsNotice>::CreateLambda([&lobby](const FAccelByteModelsDsNotice& Result)
{
if (Result.Status == "READY" || Result.Status == "BUSY")
{
// DS is ready to be joined
}
}));

FRegistry::Lobby.SendStartMatchmaking("game_mode");

Check a Joinable Session's Status

When a server is claimed, it will query the session details from the Matchmaking service. The game server will determine whether the session is joinable or not by calling the following function.

FString MatchId = "testMatchId";
FAccelByteMatchmakingResult SessionData;
AccelByte::FRegistry::ServerDSM.QuerySessionStatus(
MatchId,
THandler<FAccelByteMatchmakingResult>::CreateLambda(
[&SessionData](const FAccelByteMatchmakingResult& Result)
{
SessionData = Result;
if (Result.joinable)
{
UE_LOG(LogTemp, Log, TEXT("Session is joinable"));
}
else
{
UE_LOG(LogTemp, Log, TEXT("Session is joinable"));
}
}),
FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
UE_LOG(LogTemp, Log, TEXT("Error query session status"));
}
));

Enqueue a Session

When receiving a joinable session, the game server will enqueue the session to the Matchmaking service as soon as it is ready to accept more players. To enqueue a session, use the following function.

AccelByte::FRegistry::ServerDSM.EnqueueJoinableSession(
SessionData,
FVoidHandler::CreateLambda([]()
{
UE_LOG(LogTemp, Log, TEXT("Enqueue Session Success"));
}),
FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
UE_LOG(LogTemp, Log, TEXT("Enqueue Session Success Failed"));
}
));

After the game server enqueues a session, players who are already matched into the session can connect to the Lobby.

Update a Session

To ensure that the session in the queue is accurate, any time a player leaves during the Lobby phase, the server will update the session in the queue. To make this update, use the function below.

FString gameMode = sessionQueryResult.Game_mode;
FString matchId = sessionQueryResult.Match_id;
FString userId;
FRegistry::ServerMatchmaking.RemoveUserFromSession(gameMode, matchId, userId, FVoidHandler::CreateLambda([]()
{
UE_LOG(LogTemp, Log, TEXT("Remove user success"));
}), FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
UE_LOG(LogTemp, Log, TEXT("Remove user Failed"));
}));

Dequeue a Session

When the game is about to start, the game server will dequeue the session to prevent the Matchmaking service from matching a new player into it. To dequeue a session, use the following function.

FString matchId;
AccelByte::FRegistry::ServerDSM.DequeueJoinableSession(
matchId,
FVoidHandler::CreateLambda([]()
{
UE_LOG(LogTemp, Log, TEXT("Enqueue Session Success"));
}),
FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
UE_LOG(LogTemp, Log, TEXT("Enqueue Session Success Failed"));
}
));