Connect to the Lobby service
Overview
The Lobby service is a component under the Play service which acts as the main hub for your player activity. This service provides a continuous connection between your players and also acts as the entry point for the game client to interact with the Friends and Presence services.
This How-to will walk you through connecting your game to the AccelByte Gaming Services (AGS) Lobby service using AccelByte OSS (OSS), Unreal Engine, and Unity.
Prerequisite
- Access to the AGS Admin Portal.
- If you're using Unreal Engine or Unity, you must have installed the AccelByte Unreal or Unity SDK. This includes credentials for your game client:
- Client ID
- Client Secret
Connect your game to the Lobby service
To connect your game to the Lobby service, follow the SDK installation steps for your game engine.
- AccelByte OSS
- Unreal Engine
- Unity
- Go Extend SDK
- Python Extend SDK
- Java Extend SDK
- C# Extend SDK
There are two ways to connect to the Lobby service in the AccelByte Online Subsystem (OSS):
Automatically connect to the Lobby
Set the bAutoLobbyConnectAfterLoginSuccess
parameter to true in the [OnlineSubsystemAccelByte]
inside the DefaultEngine.ini
file. Once set, OSS will try to connect to the lobby upon a successful user login.
Manually connect to the Lobby
If the automatic option does not work, you can manually call FOnlineIdentityAccelByte::ConnectAccelByteLobby
by running this command.
// Manually connect to lobby
int32 LocalUserNum = 0;
FOnlineIdentityAccelBytePtr IdentityInterface = StaticCastSharedPtr<FOnlineIdentityAccelByte>(OnlineSubsystem->GetIdentityInterface());
AB_TEST_TRUE(IdentityInterface.IsValid());
IdentityInterface->ConnectAccelByteLobby(LocalUserNum);
AccelByte::FRegistry::Lobby.Connect();
AccelBytePlugin.GetLobby().Connect();
connectionutils.NewWebsocketConnection(&configRepo, &tokenRepo, lobbyMessageHandler)
import asyncio
import accelbyte_py_sdk.services.auth as auth_service
from accelbyte_py_sdk.core import AccelByteSDK
from accelbyte_py_sdk.core import MyConfigRepository
from accelbyte_py_sdk.core import HttpxHttpClient
from accelbyte_py_sdk.core import InMemoryTokenRepository
from accelbyte_py_sdk.core import WebsocketsWSClient
config_repo = MyConfigRepository(
base_url="https://****.accelbyte.io",
client_id="********************************",
client_secret="********************************",
namespace="********",
)
token_repo = InMemoryTokenRepository()
sdk = AccelByteSDK()
sdk.initialize(
options={
"config": config_repo,
"token": token_repo,
"http": HttpxHttpClient(),
}
)
result, error = await auth_service.login_user_async(
username="********",
password="********",
sdk=sdk,
)
if error:
exit(error)
ws_client = WebsocketsWSClient(
uri=config_repo.get_base_url(),
access_token=token_repo.get_access_token(),
)
await ws_client.connect()
# do something
await ws_client.disconnect()
import okhttp3.Response;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
import net.accelbyte.sdk.api.lobby.ws_models.MessageNotif;
public class MyLobby extends WebSocketListener {
...
private OkhttpWebSocketClient wsClient;
public MyLobby(...) {
...
wsClient = OkhttpWebSocketClient.create(configRepository, tokenRepository, this);
}
@Override
public void onMessage(@NotNull WebSocket webSocket, @NotNull String text) {
super.onMessage(webSocket, text);
if (text.contains(MessageNotif.getType())) {
final MessageNotif notif = MessageNotif.createFromWSM(text);
...
}
}
@Override
public void onOpen(@NotNull WebSocket webSocket, @NotNull Response response) {
super.onOpen(webSocket, response);
}
@Override
public void onClosed(@NotNull WebSocket webSocket, int code, @NotNull String reason) {
super.onClosed(webSocket, code, reason);
}
@Override
public void onClosing(@NotNull WebSocket webSocket, int code, @NotNull String reason) {
super.onClosing(webSocket, code, reason);
}
@Override
public void onFailure(@NotNull WebSocket webSocket, @NotNull Throwable t, @Nullable Response response) {
super.onFailure(webSocket, t, response);
}
LobbyService lobby = new LobbyService(sdk.Configuration);
//async
await lobby.Connect(false);
//sync
Task connectTak = lobby.Connect(false);
connectTak.Wait();
What's next?
After you have connected your game to the Lobby service, your game lobby is created. Configure the settings for your game's lobby in the AGS Admin Portal. See Configure the Lobby service.