Loading...
Searching...
No Matches
FOnlineUserCacheAccelByte Class Reference

#include <OnlineUserCacheAccelByte.h>

Public Member Functions

bool QueryUsersByAccelByteIds (int32 LocalUserNum, const TArray< FString > &AccelByteIds, const FOnQueryUsersComplete &Delegate, bool bIsImportant=false)
bool QueryUsersByPlatformIds (int32 LocalUserNum, const FString &PlatformType, const TArray< FString > &PlatformIds, const FOnQueryUsersComplete &Delegate, bool bIsImportant=false)
bool QueryUsersByAccelByteIds (const FUniqueNetId &UserId, const TArray< FString > &AccelByteIds, const FOnQueryUsersComplete &Delegate, bool bIsImportant=false)
bool QueryUsersByPlatformIds (const FUniqueNetId &UserId, const FString &PlatformType, const TArray< FString > &PlatformIds, const FOnQueryUsersComplete &Delegate, bool bIsImportant=false)
TSharedPtr< const FAccelByteUserInfo, ESPMode::ThreadSafe > GetUser (const FUniqueNetId &UserId)
TSharedPtr< const FAccelByteUserInfo, ESPMode::ThreadSafe > GetUser (const FAccelByteUniqueIdComposite &UserId)
bool IsStalenessCheckEnabled () const
double GetTimeUntilStaleSeconds () const
void SetStalenessCheckEnabled (bool bInEnableStalenessChecking)
void SetTimeUntilStaleSeconds (double InTimeUntilStaleSeconds)
bool SetUserDataAsStale (const FUniqueNetId &UserUniqueId)
bool SetUserDataAsStale (const FString &InAccelByteId)
bool IsUserDataStale (const FUniqueNetId &UserUniqueId)
bool IsUserDataStale (const FString &InAccelByteId)
void Init ()
void AddUsersToCache (const TArray< FAccelByteUserInfoRef > &UsersQueried)
void AddPublicCodeToCache (const FUniqueNetId &UserId, const FString &PublicCode)
void AddPublicCodeToCache (const FAccelByteUniqueIdComposite &UserId, const FString &PublicCode)
void AddLinkedPlatformInfoToCache (const FUniqueNetId &UserId, const TArray< FAccelByteLinkedUserInfo > &LinkedPlatformInfo)
void AddLinkedPlatformInfoToCache (const FAccelByteUniqueIdComposite &UserId, const TArray< FAccelByteLinkedUserInfo > &LinkedPlatformInfo)
int32 Purge ()
bool IsUserCached (const FAccelByteUniqueIdComposite &Id)
void GetQueryAndCacheArrays (const TArray< FString > &AccelByteIds, TArray< FString > &UsersToQuery, TArray< FAccelByteUserInfoRef > &UsersInCache)

Static Public Member Functions

static bool GetFromSubsystem (const IOnlineSubsystem *Subsystem, TSharedPtr< FOnlineUserCacheAccelByte, ESPMode::ThreadSafe > &OutInterfaceInstance)
static bool GetFromWorld (const UWorld *World, TSharedPtr< FOnlineUserCacheAccelByte, ESPMode::ThreadSafe > &OutInterfaceInstance)

Public Attributes

PACKAGE_SCOPE : FOnlineUserCacheAccelByte(FOnlineSubsystemAccelByte* InSubsystem)

Detailed Description

Manages users that are queried from the AccelByte backend, making bulk calls to retrieve user data, as well as getting extra necessary information for those users, such as platform IDs relevant to the current native platform.

As an explanation of how this works under the hood, the cache is made of shared FAccelByteUserInfo instances that are put into two maps. One map is for mapping the AccelByte ID to the user's information, and one is for mapping platform information to the user's information. This way either can be queried seamlessly to get the same user data. The only time you won't be able to query a user by their platform IDs is if they are not on the same platform as you, in which you can only query by AccelByte ID.

User data will be kept cached based on how long it has been since they have been accessed. You can configure how long users will stay in cache with the UserCachePurgeTimeoutSeconds variable in the OnlineSubsystemAccelByte settings in DefaultEngine.ini. Users will also not be purged if they were marked as important when queried.

Member Function Documentation

◆ AddLinkedPlatformInfoToCache() [1/2]

void FOnlineUserCacheAccelByte::AddLinkedPlatformInfoToCache ( const FAccelByteUniqueIdComposite & UserId,
const TArray< FAccelByteLinkedUserInfo > & LinkedPlatformInfo )

Adds linked platform information to the user cache for a given composite user ID. Creates a new cache entry if the user does not already exist in the cache.

◆ AddLinkedPlatformInfoToCache() [2/2]

void FOnlineUserCacheAccelByte::AddLinkedPlatformInfoToCache ( const FUniqueNetId & UserId,
const TArray< FAccelByteLinkedUserInfo > & LinkedPlatformInfo )

Adds linked platform information to the user cache for a given user ID. Creates a new cache entry if the user does not already exist in the cache.

◆ AddPublicCodeToCache() [1/2]

void FOnlineUserCacheAccelByte::AddPublicCodeToCache ( const FAccelByteUniqueIdComposite & UserId,
const FString & PublicCode )

Add PublicCode to a user cache, create new if not exist

◆ AddPublicCodeToCache() [2/2]

void FOnlineUserCacheAccelByte::AddPublicCodeToCache ( const FUniqueNetId & UserId,
const FString & PublicCode )

Add PublicCode to a user cache, create new if not exist

◆ AddUsersToCache()

void FOnlineUserCacheAccelByte::AddUsersToCache ( const TArray< FAccelByteUserInfoRef > & UsersQueried)

Add an array of freshly queried users to the user cache

◆ GetFromSubsystem()

bool FOnlineUserCacheAccelByte::GetFromSubsystem ( const IOnlineSubsystem * Subsystem,
TSharedPtr< FOnlineUserCacheAccelByte, ESPMode::ThreadSafe > & OutInterfaceInstance )
static

Convenience method to get an instance of this interface from the subsystem passed in.

Parameters
SubsystemSubsystem instance that we wish to get this interface from
OutInterfaceInstanceInstance of the interface that we got from the subsystem, or nullptr if not found
Returns
boolean that is true if we could get an instance of the interface, false otherwise

◆ GetFromWorld()

bool FOnlineUserCacheAccelByte::GetFromWorld ( const UWorld * World,
TSharedPtr< FOnlineUserCacheAccelByte, ESPMode::ThreadSafe > & OutInterfaceInstance )
static

Convenience method to get an instance of this interface from the subsystem associated with the world passed in.

Parameters
WorldWorld instance that we wish to get the interface from
OutInterfaceInstanceInstance of the interface that we got from the subsystem, or nullptr if not found
Returns
boolean that is true if we could get an instance of the interface, false otherwise

◆ GetQueryAndCacheArrays()

void FOnlineUserCacheAccelByte::GetQueryAndCacheArrays ( const TArray< FString > & AccelByteIds,
TArray< FString > & UsersToQuery,
TArray< FAccelByteUserInfoRef > & UsersInCache )

Method used by user queries to get an array of users that we still need to query, as well as shared instances to users that we have already queried and can retrieve from the cache

◆ GetTimeUntilStaleSeconds()

double FOnlineUserCacheAccelByte::GetTimeUntilStaleSeconds ( ) const

Returns the length of time in seconds that it takes for a user's cached data to become stale.

◆ GetUser() [1/2]

TSharedPtr< const FAccelByteUserInfo, ESPMode::ThreadSafe > FOnlineUserCacheAccelByte::GetUser ( const FAccelByteUniqueIdComposite & UserId)

Attempt to get a user from the cache by a composite ID structure.

◆ GetUser() [2/2]

TSharedPtr< const FAccelByteUserInfo, ESPMode::ThreadSafe > FOnlineUserCacheAccelByte::GetUser ( const FUniqueNetId & UserId)

Attempt to get a user from the cache by an AccelByte unique ID. This ID comes from either an FAccelByteUserInfo::Id field, or from the result of a query users call.

◆ Init()

void FOnlineUserCacheAccelByte::Init ( )

Initialize the user cache. This will load configuration values from the engine INI for the cache. Called from the subsystem initialization method.

◆ IsStalenessCheckEnabled()

bool FOnlineUserCacheAccelByte::IsStalenessCheckEnabled ( ) const

Checks if staleness checks for cached user data is enabled.

◆ IsUserCached()

bool FOnlineUserCacheAccelByte::IsUserCached ( const FAccelByteUniqueIdComposite & Id)

Check whether a user exists already in the cache so that we don't requery them.

◆ IsUserDataStale() [1/2]

bool FOnlineUserCacheAccelByte::IsUserDataStale ( const FString & InAccelByteId)

Check whether user's cached data has become stale.

Parameters
InAccelByteIdString representation of the user ID that you wish to check the staleness
Returns
true if data stale, false otherwise

◆ IsUserDataStale() [2/2]

bool FOnlineUserCacheAccelByte::IsUserDataStale ( const FUniqueNetId & UserUniqueId)

Check whether user's cached data has become stale.

Parameters
UserUniqueIdUnique ID of the user that we wish to check the staleness, must be an AccelByte unique ID
Returns
true if data stale, false otherwise

◆ Purge()

int32 FOnlineUserCacheAccelByte::Purge ( )

Searches through the user caches for a user that hasn't been accessed in longer than the maximum time set for this cache. If a user is found that exceeds this max time, and they are not marked as important, they will be removed from the cache entirely.

Will return the number of users purged from the cache.

Do not call this method directly, it will be called from the owning OnlineSubsystem's ticker!

◆ QueryUsersByAccelByteIds() [1/2]

bool FOnlineUserCacheAccelByte::QueryUsersByAccelByteIds ( const FUniqueNetId & UserId,
const TArray< FString > & AccelByteIds,
const FOnQueryUsersComplete & Delegate,
bool bIsImportant = false )

Queries all of the IDs listed in the array on the AccelByte backend for user information, including platform IDs. If platform IDs are found and match the current platform that we are on, extra queries will be made through the platform OSSes.

Caches any results that we get from the backend, as well as will not query from the backend again if a duplicate is found.

Parameters
UserIdFUniqueNetId of the user that is attempting to query for users
AccelByteIdsArray of strings that represent an ID for a single user
DelegateDelegate fired when the query is complete
bIsImportantWhether or not we want to mark these users as important so that they stay in the cache, defaults to false. This should only be used for users that we want to persist for the length of the game session, such as friends.

◆ QueryUsersByAccelByteIds() [2/2]

bool FOnlineUserCacheAccelByte::QueryUsersByAccelByteIds ( int32 LocalUserNum,
const TArray< FString > & AccelByteIds,
const FOnQueryUsersComplete & Delegate,
bool bIsImportant = false )

Queries all of the IDs listed in the array on the AccelByte backend for user information, including platform IDs. If platform IDs are found and match the current platform that we are on, extra queries will be made through the platform OSSes.

Caches any results that we get from the backend, as well as will not query from the backend again if a duplicate is found.

Parameters
LocalUserNumIndex of the user that is attempting to query for other users
AccelByteIdsArray of strings that represent an ID for a single user
DelegateDelegate fired when the query is complete
bIsImportantWhether or not we want to mark these users as important so that they stay in the cache, defaults to false. This should only be used for users that we want to persist for the length of the game session, such as friends.

◆ QueryUsersByPlatformIds() [1/2]

bool FOnlineUserCacheAccelByte::QueryUsersByPlatformIds ( const FUniqueNetId & UserId,
const FString & PlatformType,
const TArray< FString > & PlatformIds,
const FOnQueryUsersComplete & Delegate,
bool bIsImportant = false )

Tries to query all platform IDs listed for the particular platform specified on the AccelByte backend to find AccelByte user matches. If a matches are found, a subsequent query and cache will be performed to get information from the AccelByte backend on those users.

Parameters
UserIdFUniqueNetId of the user that is attempting to query for users
PlatformTypeString representing the type of platform that these IDs belong to
PlatformIdsArray of strings that represent an ID for a single user
DelegateDelegate fired when the query is complete
bIsImportantWhether or not we want to mark these users as important so that they stay in the cache, defaults to false. This should only be used for users that we want to persist for the length of the game session, such as friends.

◆ QueryUsersByPlatformIds() [2/2]

bool FOnlineUserCacheAccelByte::QueryUsersByPlatformIds ( int32 LocalUserNum,
const FString & PlatformType,
const TArray< FString > & PlatformIds,
const FOnQueryUsersComplete & Delegate,
bool bIsImportant = false )

Tries to query all platform IDs listed for the particular platform specified on the AccelByte backend to find AccelByte user matches. If a matches are found, a subsequent query and cache will be performed to get information from the AccelByte backend on those users.

Parameters
LocalUserNumIndex of the user that is attempting to query for other users
PlatformTypeString representing the type of platform that these IDs belong to
PlatformIdsArray of strings that represent an ID for a single user
DelegateDelegate fired when the query is complete
bIsImportantWhether or not we want to mark these users as important so that they stay in the cache, defaults to false. This should only be used for users that we want to persist for the length of the game session, such as friends.

◆ SetStalenessCheckEnabled()

void FOnlineUserCacheAccelByte::SetStalenessCheckEnabled ( bool bInEnableStalenessChecking)

Enable or disable staleness checks in the user cache. Intended for runtime testing of cache. Prefer using ini or command line to enable or disable staleness checks.

◆ SetTimeUntilStaleSeconds()

void FOnlineUserCacheAccelByte::SetTimeUntilStaleSeconds ( double InTimeUntilStaleSeconds)

Set the amount of time in seconds that it takes for a user's cached data to become stale. Intended for runtime testing of cache. Prefer using ini or command line to control staleness time.

◆ SetUserDataAsStale() [1/2]

bool FOnlineUserCacheAccelByte::SetUserDataAsStale ( const FString & InAccelByteId)

Attempts to mark the referenced user's cached data as stale. If found, the force stale flag on the user's data will be updated, and the next request to get user data will request new data for this user, regardless of whether the stale datetime has been reached. This flag will be reset after the request is processed.

Parameters
InAccelByteIdString representation of the user ID that you wish to mark stale
Returns
true if flag was set, false otherwise

◆ SetUserDataAsStale() [2/2]

bool FOnlineUserCacheAccelByte::SetUserDataAsStale ( const FUniqueNetId & UserUniqueId)

Attempts to mark the referenced user's cached data as stale. If found, the force stale flag on the user's data will be updated, and the next request to get user data will request new data for this user, regardless of whether the stale datetime has been reached. This flag will be reset after the request is processed.

Parameters
UserUniqueIdUnique ID of the user that we wish to set as stale, must be an AccelByte unique ID
Returns
true if flag was set, false otherwise