Git Product home page Git Product logo

accelbyte-unreal-oss's Introduction

AccelByte Online Subsystem

Overview

AccelByte Cloud Online Subsystem (OSS) is the high-level bridge between Unreal Engine and AccelByte services that comprises interfaces that access AccelByte services and its features. The AccelByte Cloud OSS is designed to handle higher level logic with asynchronous communication and delegates, and is also designed to be modular by grouping similar service-specific APIs that support features together.

Getting Started

Dependencies

AccelByte OSS have some dependencies to another Plugins/Modules, such as the following:

  1. AccelByte Cloud Unreal Engine SDK (link): a library that comprises APIs for the game client and game server to send requests to AccelByte services.
  2. AccelByte Cloud Network Utilities (link): a library that comprises network functionalities to communicate between game clients for P2P networking.

Configuration

To use AccelByte OSS, some configurations need to be set up first as follows:

  1. Add required plugins to .uproject file
"Plugins": [
  {
     "Name": "AccelByteUe4Sdk",
     "Enabled": true
  },
  {
     "Name": "OnlineSubsystemAccelByte",
     "Enabled": true
  },
  {
     "Name": "AccelByteNetworkUtilities",
     "Enabled": true
  },
  ...
]
  1. Add public dependency module to the Build.cs file
PublicDependencyModuleNames.AddRange(new string[] { 
  "AccelByteUe4Sdk",
  "AccelByteNetworkUtilities",
  "OnlineSubsystemAccelByte"
});
  1. Add the following modules to the Target.cs file
ExtraModuleNames.AddRange( new string[] { 
  "AccelByteUe4Sdk",
  "OnlineSubsystemAccelByte",
  "AccelByteNetworkUtilities"
});
  1. Edit the DefaultEngine.ini to include the following settings
[OnlineSubsystem]
DefaultPlatformService=AccelByte
; Specifies the name of the platform-specific OSS
NativePlatformService=

[OnlineSubsystemAccelByte]
bEnabled=true
; Enable/Disable multiple local users support
bMultipleLocalUsersEnabled=false
; Specifies to automatically connect to Lobby WebSocket
bAutoLobbyConnectAfterLoginSuccess=true
  1. Edit the platform specific config ini file located inside the platform's folder (e.g. Config/Windows/WindowsEngine.ini)
; Set the OSS configs for Windows to use the AccelByte OSS 
; as the default subsystem, and Steam as the native
[OnlineSubsystem]
NativePlatformService=Steam

[OnlineSubsystemSteam]
bEnabled=true
bUseSteamNetworking=false
SteamDevAppId=<game_app_id>

LocalUserNum

The AccelByte Cloud OSS is able to handle multiple local users playing in the same game instance, by identifying the controller index of the users. The same controller index is defined as LocalUserNum in most of OSS interfaces. The AccelByte Cloud OSS stores user online information using LocalUserNum as the key.

UniqueNetId

UniqueNetId is the abstraction of the user’s profile in Online services. In AccelByte Cloud OSS, it is derived as AccelByte Composite UniqueNetId and consists of AccelByte userId, originating platform, and originating platform userId data fields.

Interfaces

The OSS has predefined interfaces which can be extended to some degrees, and AccelByte OSS has extended some of the interfaces which game developers can integrate it to their games. These interfaces will wrap the APIs in asynchronous calls so the game can still run as usual.

Online Identity Interface

Online Identity Interface is used for player registration/authentication

Try this first

When initially adding the AccelByte OSS to your game, try registering/authentication a headless account via DeviceId. This is the simplest and most reliable* method of registration/authentication. "Reliable" here meaning "fewest remote/moving pieces, and most likely to work". Your system's device ID can change, such as by a change in what hardware is installed, so it should not be relied upon for real player accounts.

// TODO: Description of _when_ this should be done in Unreal's flow.
void TestAbRegistrationAuthentication()
{
   // Note that FRegistry is also in your global namespace.
   // The AccelByte namespace is added here for clarity.
   AccelByte::FRegistry::User.LoginWithDeviceId(
      FVoidHandler::CreateLambda([&]()
      {
         // This copy-paste example uses a generally-present log category in Unreal.
         // See Unreal's "DECLARE_LOG_CATEGORY_EXTERN()" to make a new log category.
         // In lieu of one, the message here is prefixed with "[AB]".
         UE_LOG(LogInit, Log, TEXT("[AB] DEVICE ID LOGIN SUCCESS!"));
      }),
      FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
      {
         UE_LOG(LogInit, Log, TEXT("[AB] Error [%d] while logging in: %s"), ErrorCode, *ErrorMessage);
      })
   );
}

Login

The AccelByte Cloud OSS offers several different login types based on the native platform or with other platforms by providing the type and credentials in th FOnlineAccountCrdentialsAccelByte class.

Login Type

There are several login types available in the AccelByte Cloud OSS. These login types are categorized as enumerations in EAccelByteLoginType and the types include:

  • DeviceId
  • AccelByte
  • Xbox
  • PS4
  • PS5
  • Launcher
  • Steam
  • RefreshToken
const FOnlineIdentityAccelBytePtr IdentityInterface = FOnlineIdentityAccelByte::Get();
 
if (IdentityInterface.IsValid())
{
   FOnlineAccountCredentialsAccelByte Credentials{ EAccelByteLoginType::AccelByte
         , Username, Password };
   // Login
   IdentityInterface->AddOnLoginCompleteDelegate_Handle(LocalUserNum
      , FOnLoginCompleteDelegate::CreateLambda([](int32 LocalUserNum, bool bLoginWasSuccessful, const FUniqueNetId& UserId, const FString& LoginError)
         {
            if (bLoginWasSuccessful)
            {
               // Do something when player successfully logged in
            } 
            else
            {
               // Do something when player failed to log in
            }
         })
      );
   IdentityInterface->Login(LocalUserNum, Credentials);
}

After successfully loggin in, the user will need to connect to Lobby to be able to use social-related interfaces and multiplayer features such as Friends, Party, Presence, Matchmaking. The user can connect to Lobby manually by calling ConnectAccelByteLobby or by setting bAutoLobbyConnectAfterLoginSucces to true in DefaultEngine.ini

const FOnlineIdentityAccelBytePtr IdentityInterface = FOnlineIdentityAccelByte::Get();
 
if (IdentityInterface.IsValid())
{
   // Connect to AccelByte Lobby Websocket, can be automatically called after
   // successful login by configuring bAutoLobbyConnectAfterLoginSuccess to true
   // in DefaultEngine.ini
   IdentityInterface->ConnectAccelByteLobby(LocalUserNum);
}
Logout

When the user is finished playing, log out using the following code

const FOnlineIdentityAccelBytePtr IdentityInterface = FOnlineIdentityAccelByte::Get();
 
if (IdentityInterface.IsValid())
{
   // Logout
   IdentityInterface->AddOnLogoutCompleteDelegate_Handle(LocalUserNum
      , FOnLogoutCompleteDelegate::CreateLambda([](int32 LocalUserNum, bool bLogoutWasSuccessful)
         {
            if (bLogoutWasSuccessful)
            {
               // Do something when player successfully logged out
            } 
            else
            {
               // Do something when player failed to log out
            }
         })
      );
   IdentityInterface->Logout(LocalUserNum);
}

accelbyte-unreal-oss's People

Contributors

wijanarko-ab avatar accelbyte-build avatar chris-barrett-fw avatar ron-prestenback-ab avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.