Session Browser
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.
Usage | Resource | Action |
---|---|---|
Create Session | NAMESPACE:{namespace}:SESSIONBROWSER:SESSION | Create |
Retrieve List of Game Sessions | ADMIN:NAMESPACE:{namespace}:SESSIONBROWSER:SESSION | Read |
Retrieve Game Session by Session ID | ADMIN:NAMESPACE:{namespace}:SESSIONBROWSER:SESSION | Read |
Update Session | NAMESPACE:{namespace}:SESSIONBROWSER:SESSION | Update |
Delete Session | NAMESPACE:{namespace}:SESSIONBROWSER:SESSION | Delete |
Join Session | NAMESPACE:{namespace}:SESSIONBROWSER:SESSION | Read |
Register Player to Session | NAMESPACE:{namespace}:SESSIONBROWSER:SESSION | Update |
Unregister Player to Session | NAMESPACE:{namespace}:SESSIONBROWSER:SESSION | Update |
Get Recent Player Data | NAMESPACE:{namespace}:SESSIONBROWSER:RECENTPLAYER | Read |
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:
- Create your OAuth Client and assign the necessary permissions to access the Achievement service.
- Log in as a Client using the SDK.
- Initialize the service using the following function:
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:
Create your OAuth Client and assign the necessary permissions to access the Achievement service.
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:
- Golang
- Python
- C#
- Java
ok, err := sessionService.CreateSession(input)
if err != nil {
return err
}
return nil
from accelbyte_py_sdk.api.sessionbrowser import create_session
from accelbyte_py_sdk.api.sessionbrowser.models import ModelsCreateSessionRequest
from accelbyte_py_sdk.api.sessionbrowser.models import ModelsGameSessionSetting
result, error = create_session(
body=ModelsCreateSessionRequest.create(
game_session_setting=ModelsGameSessionSetting.create(
allow_join_in_progress=False,
current_internal_player=0,
current_player=0,
map_name="<map-name>",
max_internal_player=10,
max_player=10,
mode="<mode>",
num_bot=0,
password="",
settings={}
),
game_version="<game-version>",
namespace="<namespace>",
session_type="<session-type>",
username="<username>"
)
)
if error:
print(error)
Session wSBSession = new Session(sdk);
ModelsCreateSessionRequest createSession = new ModelsCreateSessionRequest()
{
SessionType = "p2p",
GameVersion = "0.3.0",
Namespace = sdk.Namespace,
Username = "<user_name>",
GameSessionSetting = new ModelsGameSessionSetting()
{
Mode = "<mode>",
AllowJoinInProgress = true,
MapName = "<map_name>",
MaxPlayer = 100
}
};
ModelsSessionResponse? cResp = wSBSession.CreateSession(
CreateSession.Builder
.Build(createSession, sdk.Namespace));
ModelsCreateSessionRequest createSession = ModelsCreateSessionRequest.builder()
.namespace(namespace)
.sessionType("p2p")
.gameVersion("0.3.0")
.username(usernameToTest)
.gameSessionSetting(ModelsGameSessionSetting.builder()
.mode("deathmatch")
.allowJoinInProgress(true)
.mapName("Java SDK Integration Test")
.maxPlayer(100)
.build())
.build();
ModelsSessionResponse cResp = wSBSession.createSession(
CreateSession.builder()
.namespace(namespace)
.body(createSession)
.build());
Delete a Session
Use the following function to delete a session using the session ID:
- Golang
- Python
- C#
- Java
ok, err := sessionService.DeleteSession(input)
if err != nil {
return err
}
return nil
from accelbyte_py_sdk.api.sessionbrowser import delete_session
result, error = delete_session(
session_id="<session-id>"
)
if error:
print(error)
Session wSBSession = new Session(sdk);
ModelsSessionResponse? dResp = wSBSession.DeleteSession(
DeleteSession.Builder
.Build(sdk.Namespace, "<session_id>"));
ModelsSessionResponse dResp = wSBSession.deleteSession(
DeleteSession.builder()
.namespace(namespace)
.sessionID(session_id)
.build());
Retrieve a Session
Use the following function to retrieve a session using the session ID:
- Golang
- Python
- C#
- Java
ok, err := sessionService.GetSession(input)
if err != nil {
return err
}
return nil
from accelbyte_py_sdk.api.sessionbrowser import get_session
result, error = get_session(
session_id="<session-id>"
)
if error:
print(error)
Session wSBSession = new Session(sdk);
ModelsSessionResponse? gResp = wSBSession.GetSession(
GetSession.Builder
.Build(sdk.Namespace, "<session_id>"));
ModelsSessionResponse gResp = wSBSession.getSession(
GetSession.builder()
.namespace(namespace)
.sessionID(session_id)
.build());
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.
- Golang
- Python
- C#
- Java
ok, err := sessionService.UpdateSession(input)
if err != nil {
return err
}
return nil
from accelbyte_py_sdk.api.sessionbrowser import update_session
from accelbyte_py_sdk.api.sessionbrowser.models import ModelsUpdateSessionRequest
result, error = update_session(
body=ModelsUpdateSessionRequest.create(
game_current_player=10,
game_max_player=20
),
session_id="<session-id>"
)
if error:
print(error)
Session wSBSession = new Session(sdk);
ModelsUpdateSessionRequest updateSession = new ModelsUpdateSessionRequest()
{
GameMaxPlayer = 150
};
ModelsSessionResponse? uResp = wSBSession.UpdateSession(
UpdateSession.Builder
.Build(updateSession, sdk.Namespace, "<session_id>"));
ModelsUpdateSessionRequest updateSession = ModelsUpdateSessionRequest.builder()
.gameMaxPlayer(150)
.build();
ModelsSessionResponse uResp = wSBSession.updateSession(
UpdateSession.builder()
.namespace(namespace)
.sessionID(sessionId)
.body(updateSession)
.build());