専用サーバーの準備完了告知の手動送信を統合する
Overview
This guideline is to enable Manual Dedicated Server (DS) Session Ready for the Dedicated Server (DS) flow. The flow on the game client side remains the same.
In your game, you can use the matchmaking, session, and Accelbyte Multiplayers Server (AMS) service out of the box to create an online multiplayer experience for a player. The general AGS Matchmaking flow in shown in the following diagram.
Players submit a matchmaking request to the AccelByte Gaming Services (AGS) Matchmaking service. When the service finds a match, it will create a game session and add the matched players as the session members. The player will get a notification for a match found along with the session information to join. The session service will then claim the Dedicated Server (DS) from the AMS. By default, when the session service successfully claims the 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.
However, 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 what game mode for the players, or pulling the players' statistical information to spawn the enemy level. If the players join the DS during the initial boot-up process, the players could have a bad experience or even be stuck infinitely. In this case, the game developers usually want the DS to decide when to notify the players about the readiness. In these cases, the flow would change to this diagram:
Game developers can enable this flow by calling the session service when the DS is ready to accept players. This flow will be explained in more detail in the next section.
Prerequisites
Before following this guideline, you should 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
Configure the Session Template
In our session template, we need to enable the “Manual Set Ready for Dedicated Server (DS)” option.
Require Permission
You will need to add this permission 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 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 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 has been successful
}
});