Skip to main content

Session Browser

Last updated on

Overview

AccelByte Cloud's Session Browser is used to store your game session data. This browser supports P2P sessions to store game clients and a Dedicated Server to store game server sessions. Both P2P and Dedicated Server sessions use REST API for the game client and server.

P2P

P2P sessions are generated by a game client and act as a session host. P2P entries contain game client session data which are stored in the session browser. When the lobby is disconnected, the P2P entries are removed from the server. If the lobby connection is reconnected by the host, past P2P entries will not be listed in the server browser and must be recreated in the session browser.

Dedicated Server (DS)

A Dedicated Server session is a session generated by the server that is managed by Armada.

  • If the server is managed by Armada, the Session browser will listen to events broadcast from our Dedicated Server Manager Controller (DSMC) and Matchmaking service. The game's Dedicated Server (DS) only needs to interact with those services, and so the data in the session browser is automatically updated.
  • If the server is not managed by Armada, we provide REST APIs in our SDK so the DS session can also be managed via the session browser, even if the DS is not managed with Armada.

Permissions

Permissions are used to grant access to specific resources within our services. Make sure your account has the following permissions before you attempt to manage the Session Browser.

UsageResourceAction
Create SessionNAMESPACE:{namespace}:SESSIONBROWSER:SESSIONCreate
Retrieve List of Game SessionsADMIN:NAMESPACE:{namespace}:SESSIONBROWSER:SESSIONRead
Retrieve Game Session by Session IDADMIN:NAMESPACE:{namespace}:SESSIONBROWSER:SESSIONRead
Update SessionNAMESPACE:{namespace}:SESSIONBROWSER:SESSIONUpdate
Delete SessionNAMESPACE:{namespace}:SESSIONBROWSER:SESSIONDelete
Join SessionNAMESPACE:{namespace}:SESSIONBROWSER:SESSIONRead
Register Player to SessionNAMESPACE:{namespace}:SESSIONBROWSER:SESSIONUpdate
Unregister Player to SessionNAMESPACE:{namespace}:SESSIONBROWSER:SESSIONUpdate
Get Recent Player DataNAMESPACE:{namespace}:SESSIONBROWSER:RECENTPLAYERRead

Permissions work slightly differently depending on whether they are assigned to IAM Clients or on Roles assigned to users. For more information, see AccelByte's Authentication and Authorization documentation.

Prerequisites

  • Make sure you've downloaded and configured AccelByte Cloud's Unreal Engine SDK.
  • Log in as a user in Game Client if you want to implement a session browser in the game client.
  • Log in with game client credentials if you want to implement a session browser in the game server.

Call the Session Browser

Game Client

You can call the session browser from the Game Client using the following function:

FApiClientPtr ApiClient { FMultiRegistry::GetApiClient() };
ApiClient->SessionBrowser

Game Server (Dedicated Server)

You can call the session browser from the Dedicated Server using the following function:

FServerApiClientPtr ServerApiClient{ FMultiRegistry::GetServerApiClient() };

ServerApiClient->ServerSessionBrowser

Implement Session Browser with Unreal Engine's SDK

Create a Session

Call the CreateGameSession() function to create a new session. Make sure you specify the EAccelByteSessionType parameter as dedicated if you want to create a Dedicated Server session, or p2p to create a P2P session.

EAccelByteSessionType SessionType {EAccelByteSessionType::dedicated};
FString GameMode {"TestGameMode"};
FString MapName {"TestMapName"};
FString Version {"1.0.0"};
int32 BotCount {0};
int32 MaxPlayer {10};
int32 MaxSpectator {5};
FString Password {""};
TSharedPtr<FJsonObject> OtherSetting {MakeShared<FJsonObject>()};
OtherSetting->SetStringField("customfield1", "customvalue1");

ApiClient->SessionBrowser.CreateGameSession(SessionType, GameMode, MapName, Version, BotCount, MaxPlayer, MaxSpectator, Password, OtherSetting,
THandler<FAccelByteModelsSessionBrowserData>::CreateLambda([](const FAccelByteModelsSessionBrowserData& Result)
{
// Do something when request success
}), FErrorHandler::CreateLambda([](const int32 Code, const FString& Msg)
{
// Do something when request error
}));

Retrieve a List of Game Sessions

Call the SessionBrowser.GetGameSessions() function to retrieve a list of active game sessions. Make sure you specify the EAccelByteSessionType parameter as dedicated if you want to retrieve a list of Dedicated Server sessions, or p2p to list P2P sessions.

int32 indexOffset {0};
int32 itemLimit {20};

ApiClient->SessionBrowser.GetGameSessions(EAccelByteSessionType::p2p, "TestGameMode", THandler<FAccelByteModelsSessionBrowserGetResult>::CreateLambda([](const FAccelByteModelsSessionBrowserGetResult& Result)
{
// On Operation success, result is stored in Result.Sessions array
}), FErrorHandler::CreateLambda([](const int32 Code, const FString& Message)
{
// Operation failed
}), indexOffset, itemLimit);

Retrieve a Game Session by Session ID

Call the SessionBrowser.GetGameSessions() function to retrieve a specific game session. Make sure you specify the EAccelByteSessionType parameter as dedicated if you want to retrieve a Dedicated Server session, or p2p to list P2P sessions.

FString SessionId {"KnownSessionId"};

ApiClient->SessionBrowser.GetGameSession(SessionId, THandler<FAccelByteModelsSessionBrowserData>::CreateLambda([](const FAccelByteModelsSessionBrowserData& Result)
{
// On Operation success do something
}), FErrorHandler::CreateLambda([](const int32 Code, const FString& Message)
{
// Operation failed
}));

Update a Session

Call the UpdateGameSession() function to keep the ongoing session's player count updated in real-time.

FString SessionId { "KnownSessionId" };
uint32 MaxPlayer {10};
uint32 CurrentPlayerCount {5};

ApiClient->SessionBrowser.UpdateGameSession(SessionId, MaxPlayer, CurrentPlayerCount,
THandler<FAccelByteModelsSessionBrowserData>::CreateLambda([](const FAccelByteModelsSessionBrowserData& Result)
{
// Do something when request success
}), FErrorHandler::CreateLambda([](const int32 Code, const FString& Msg)
{
// Do something when request error
}));

Delete a Session

Call the RemoveGameSession() function to delete a session.

FString SessionId { "KnownSessionId" };

ApiClient->SessionBrowser.RemoveGameSession(SessionId,
THandler<FAccelByteModelsSessionBrowserData>::CreateLambda([](const FAccelByteModelsSessionBrowserData& Result)
{
// Do something when request success
}), FErrorHandler::CreateLambda([](const int32 Code, const FString& Msg)
{
// Do something when request error
}));

Join a Session

Call the JoinSession() function to join a known session. This method requires a session ID and password (if the session has a password). This function will return network data such as IP and Port that can be used to connect to a game host.

FString SessionId { "KnownSessionId" };
FString SessionPassword {"InputPassword"};

ApiClient->SessionBrowser.JoinSession(SessionId, SessionPassword,
THandler<FAccelByteModelsSessionBrowserData>::CreateLambda([](const FAccelByteModelsSessionBrowserData& Result)
{
// Do something when request success
}), FErrorHandler::CreateLambda([](const int32 Code, const FString& Msg)
{
// Do something when request error
}));

Register Player to Session

When the game host detects that a player has joined a session, the RegisterPlayer() function will be called to update the session data with the new player.

FString SessionId { "KnownSessionId" };
FString UserId { "IDToAdd"};
bool bAsSpectator {false};

ApiClient->SessionBrowser.RegisterPlayer(SessionId, UserId, bAsSpectator,
THandler<FAccelByteModelsSessionBrowserAddPlayerResponse>::CreateLambda([](const FAccelByteModelsSessionBrowserAddPlayerResponse& Result)
{
// Do something when request success
}), FErrorHandler::CreateLambda([](const int32 Code, const FString& Msg)
{
// Do something when request error
}));

Unregister Player to Session

When the game host detects that a player has left a session, the UnegisterPlayer() function will be called to remove the player from the session data.

FString SessionId { "KnownSessionId" };
FString UserId { "IdToRemove"};

ApiClient->SessionBrowser.UnregisterPlayer(SessionId, UserId,
THandler<FAccelByteModelsSessionBrowserAddPlayerResponse>::CreateLambda([](const FAccelByteModelsSessionBrowserAddPlayerResponse& Result)
{
// Do something when request success
}), FErrorHandler::CreateLambda([](const int32 Code, const FString& Msg)
{
// Do something when request error
}));

Get Recent Player Data

Call the GeRecentPlayer() function to retrieve information such as userID and displayName from recently encountered players.

FString UserId { "idToQuery"};
int32 indexOffset {0};
int32 itemLimit {10};

ApiClient->SessionBrowser.GetRecentPlayer(UserId,
THandler<FAccelByteModelsSessionBrowserRecentPlayerGetResult>::CreateLambda([](const FAccelByteModelsSessionBrowserRecentPlayerGetResult& Result)
{
// Do something when request success
}), FErrorHandler::CreateLambda([](const int32 Code, const FString& Msg)
{
// Do something when request error
}), indexOffset, itemLimit);

Connect Custom Services to the Session Browser using the Server SDKs

SDK Initialization

Before using the Session Browser service, you must initialize your server-side SDK to be authorized to perform create, read, update, and delete actions.

Golang SDK Initialization

To start using the Session Browser service from the Golang SDK, you must initialize the SDK by completing the following steps:

sessionService := &sessionbrowser.SessionService{
Client: factory.NewSessionBrowserClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}

Once you have successfully completed this initialization, you can use the Golang SDK to create, read, update, and delete Session Browsers** from your serverless app.

Python SDK Initialization

To start using the Session Browser service from the Python SDK, you must initialize the SDK by completing the following steps:

Once you have successfully completed this initialization, you can use the Python SDK to create, read, update, and delete Session Browsers from your serverless app.

.NET (C#) SDK Initialization

Before using the Session Browser service, you will need to set some permissions. Use the following .NET namespaces:

using AccelByte.Sdk.Api.Sessionbrowser.Model;
using AccelByte.Sdk.Api.Sessionbrowser.Operation;
using AccelByte.Sdk.Api.Sessionbrowser.Wrapper;

Java SDK Initialization

Before using the Session Browser service, you will need to set some permissions. Initialize the Session wrapper from the Session Browser service using the following code:

Session wSBSession = new Session(sdk);

Once completed, you can use the SDK to create, read, update, or delete sessions.

Register a New Game Session

Use the following function to create a session:

ok, err := sessionService.CreateSession(input)
if err != nil {
return err
}
return nil

Delete a Session

Use the following function to delete a session using the session ID:

ok, err := sessionService.DeleteSession(input)
if err != nil {
return err
}
return nil

Retrieve a Session

Use the following function to retrieve a session using the session ID:

ok, err := sessionService.GetSession(input)
if err != nil {
return err
}
return nil

Update a Session

Use the following function to update a session. You can update a game session when you need to update the maximum number of players or number of current players in a session.

ok, err := sessionService.UpdateSession(input)
if err != nil {
return err
}
return nil