Session Browser
Overview
AccelByte Gaming Services (AGS) Starter session browser feature stores your game session data, with support for P2P sessions to store game clients, and a Dedicated Server (DS) to store game server sessions. Both P2P and Dedicated Server sessions use REST API for the game clients and servers.
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.
P2P sessions are unique in that new sessions cannot have the same server name. As a game developer, you can also set up a password to protect your P2P session when you create the session.
Dedicated Server (DS)
A Dedicated Server session is a session generated by the server and 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 DS interacts with these services only, 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 AGS Starter SDKs so the DS session can also be managed via the session browser, even if the DS is not managed with Armada.
Prerequisites
- Make sure you’ve downloaded and configured AccelByte’s Unreal Engine SDK.
- Log in as a user in your game client if you want to implement a session browser within the game client, or
- Log in with your game client credentials if you want to implement a session browser in the game server.
Call the Session Browser
Game Client
Use the following function to call the session browser from the game client:
FApiClientPtr ApiClient { FMultiRegistry::GetApiClient() };
ApiClient->SessionBrowser
Game Server (Dedicated Server)
Use the following function to call the session browser from the DS:
FServerApiClientPtr ServerApiClient{ FMultiRegistry::GetServerApiClient() };
ServerApiClient->ServerSessionBrowser
Implement the Session Browser using the Unreal Engine 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.
- Unreal Engine
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.
- Unreal Engine
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.
- Unreal Engine
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.
- Unreal Engine
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.
- Unreal Engine
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.
- Unreal Engine
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.
- Unreal Engine
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.
- Unreal Engine
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.
- Unreal Engine
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);