Integrate manual dedicated server sessions
Overview
By default, AccelByte Gaming Services (AGS) Session works in conjunction with AGS Matchmaking and AccelByte Multiplayer Servers (AMS) to automatically add players into a session and claim a dedicated server (DS) for a match. However, there are times when a player attempts to join a DS before the DS is prepared. To prevent issues that arise as a result of this, you can implement the ability for a DS to send a notification to the session that it is ready to be joined.
This article covers the flow for this process and shows you how to implement it.
This article is for enabling a DS to manually send a session ready notification, which affects the workflow on the DS side. The flow on the game client side remains the same.
Review dedicated server matchmaking flow
In your game, you can use AGS Session, AGS Matchmaking, and AMS to create an online multiplayer experience for a player.
Default matchmaking flow
The general AGS matchmaking flow is shown in the following diagram:
Players submit a matchmaking request to AGS Matchmaking. When a match is found, a game session is created and adds the matched players as the session members. The player will get a notification for a match found along with the session information to join. AGS Session will then claim a DS from AMS. By default, when AGS Session successfully claims a DS, it will send a notification to the players with the DS information so that the players can join the DS and start playing the game.
Manual ready session flow
In some cases, the DS still needs to do preprocessing or initial tasks before it is ready to accept players. For example, getting information from player attributes, waiting for the additional data to determine the game mode for the players, or pulling the players' statistical information. If the players join the DS during the initial processes, the players could issues. In this case, game developers will want the DS to decide when to notify the players about its readiness. In these cases, the flow looks like the following diagram:
Game developers can enable this flow by calling AGS Session when the DS is ready to accept players.
Prerequisites
Before following the steps in this article, you will need to already have basic knowledge of matchmaking and joining sessions in AGS. Additionally, you should understand the process of configuring matches and sessions in the AGS Admin Portal.
Set up the manual DS session
Follow the steps in the sections below to set up manual DS sessions.
Configure the session template
In your session template, you need to enable the Manual Set Ready for Dedicated Server (DS) option.
Require permission
You will need to add the permission below to the IAM OAuth client for the DS so that the DS can manually send the DS session ready status.
Permission | Action |
---|---|
ADMIN:NAMESPACE:{namespace}:SESSION:GAME | [UPDATE] |
Send session ready using AGS Game SDK
Below is the code snippet to send the DS session ready notification using the AGS OSS. You should call this code after all the DS preparation is done. After the request is sent successfully, the game client should receive a DS status changed notification and be able to join the DS.
- OSS
- Unreal Engine
- Unity
FOnlineSessionV2AccelBytePtr SessionInterface;
FOnlineSessionV2AccelByte::GetFromWorld(GetWorld(), SessionInterface);
if (SessionInterface != nullptr)
{
SessionInterface->AddOnSendDSSessionReadyCompleteDelegate_Handle(FOnSendDSSessionReadyCompleteDelegate::CreateLambda([](const FOnlineError& ErrorInfo)
{
if (ErrorInfo.bSucceeded)
{
UE_LOG_AB(Verbose, TEXT("SEND DS READY SUCCESS!!!"));
}
}));
SessionInterface->SendDSSessionReady();
}
// Game session ID is obtained when the DS claimed, listen to ServerDSHub.SetOnServerClaimedNotificationDelegate
FString GameSessionId = TEXT("game-session-id");
auto ServerApiClient = FMultiRegistry::GetServerApiClient();
ServerApiClient->ServerSession.SendDSSessionReady(GameSessionId, true,
FVoidHandler::CreateLambda([]()
{
// Send DS session ready success. The game client will receive DS Status Changed and can travel to DS
}),
FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Send DS session ready failed
}));
var serverSession = AccelByteSDK.GetServerRegistry().GetApi().GetSession();
// Game session ID is obtained when the DS is claimed (from MatchmakingV2ServerClaimed notification in ServerDSHub)
var sessionId = "current-session-id";
serverSession.SendDSSessionReady(sessionId, true, result =>
{
{
if (result.IsError)
{
// Do something if SendDSSessionReady has an error
Debug.Log($"Error SendDSSessionReady, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if SendDSSessionReady succeeds
}
});