Connect a Game Client to the Dedicated Server
Last updated on
Make sure the player is logged in.
Call this function to request the Lobby service to start matchmaking. We provide a unique DS name to make sure that the player will connect to the local DS. An empty server name means the DSM will create an instance of a managed DS.
- Unreal Engine
- Unity
FString GameMode = FString("1v1");
FString ServerName = FString("my-awesome-game-server");
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetMatchmakingNotifDelegate(AccelByte::Api::Lobby::MatchmakingNotif.CreateLambda([](const FAccelByteModelsMatchmakingNotice& Result)
{
if (Result.Status == EAccelByteMatchmakingStatus::Done)
{
FString MatchId = Result.MatchId;
}
}));
FRegistry::Lobby.SendStartMatchmaking(GameMode, ServerName);string gameMode = "1v1";
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().StartMatchmaking(gameMode, result =>
{
if (result.IsError)
{
// Do something if StartMatchmaking has an error
Debug.Log($"Error StartMatchmaking, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if StartMatchmaking has been successful
}
});Wait for the Lobby service to send a notification that a match has been found. After you successfully found a match we suggest you save the match id to a variable that then you can use again if needed.
- Unreal Engine
- Unity
Registry::Lobby.Connect();
FRegistry::Lobby.SetMatchmakingNotifDelegate(AccelByte::Api::Lobby::MatchmakingNotif.CreateLambda([](const FAccelByteModelsMatchmakingNotice& Result)
{
if (Result.Status == EAccelByteMatchmakingStatus::Done)
{
FString MatchId = Result.MatchId;
}
}));AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().MatchmakingCompleted += result =>
{
if (result.IsError)
{
// Do something if MatchmakingCompleted has an error
Debug.Log($"Error MatchmakingCompleted, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if MatchmakingCompleted has been successful
if (result.Value.status == "Done")
{
string matchId = result.Value.matchId;
}
}
};The Lobby service will notify the game client that the player is ready to join the match using this function.
- Unreal Engine
- Unity
FString MatchId = FString("SomeMatchId");
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetReadyConsentResponseDelegate(AccelByte::Api::Lobby::ReadyConsentResponse.CreateLambda([](const FAccelByteModelsReadyConsentRequest& Result)
{
if (Result.Code == "0")
{
// Do something if ReadyConsentResponseDelegate has been successful
}
else
{
// Do something if ReadyConsentResponseDelegate has an error
}
}));
FRegistry::Lobby.SendReadyConsentRequest(MatchId);string matchId = "SomeMatchId";
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().ConfirmReadyForMatch(matchId, result =>
{
if (result.IsError)
{
// Do something if ConfirmReadyForMatch has an error
Debug.Log($"Error ConfirmReadyForMatch, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if ConfirmReadyForMatch has been successful
}
});Wait for the DS to get the match details from the Lobby service. Then, connect to the DS using those details.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetDsNotifDelegate(AccelByte::Api::Lobby::DsNotif.CreateLambda([](const FAccelByteModelsDsNotice& Result)
{
// Do something if SetDsNotifDelegate has been successful
FString IpAddress = Result.Ip;
int32 Port = Result.Port;
}));AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().DSUpdated += result =>
{
if (result.IsError)
{
// Do something if DSUpdated has an error
Debug.Log($"Error DSUpdated, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if DSUpdated has been successful
}
};