Skip to main content

Connect a Game Client to the Dedicated Server

Last updated on
  1. Make sure the player is logged in.

  2. 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.

    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);
  3. 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.

    Registry::Lobby.Connect();
    FRegistry::Lobby.SetMatchmakingNotifDelegate(AccelByte::Api::Lobby::MatchmakingNotif.CreateLambda([](const FAccelByteModelsMatchmakingNotice& Result)
    {
    if (Result.Status == EAccelByteMatchmakingStatus::Done)
    {
    FString MatchId = Result.MatchId;
    }
    }));
  4. The Lobby service will notify the game client that the player is ready to join the match using this function.

    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);
  5. Wait for the DS to get the match details from the Lobby service. Then, connect to the DS using those details.

    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;
    }));