Presence
Overview
AccelByte Gaming Services (AGS) Starter Presence services enable players to see what other players are doing. Presence services can show players if their friends are online or offline, and if they’re available to play together. We use WebSocket to ensure that a player’s presence status is updated in real-time. These services include two main features:
- Set User Presence allows clients to set a player’s availability and activity. There are five availability status options: Offline, Available, Away, Busy, and Invisible. Activity status is customizable and can include Playing Game A, In Lobby, In Match, or In Party Looking For Members.
- Get Friend Presence allows clients to show players what their friends are doing. Clients can display a player’s availability and activity status to their friends, so that players can invite friends that aren’t busy to play together.
If the service is successful, when a client sets a player’s availability code and status the that status will be visible to that player’s friends.
Implementing Presence using the SDK
Set a Player's Status
A player’s presence can be set by a game. This function is how to update the status of the player that is going to change the status.
- Unreal Engine
- Unity
Availability Availability = Availability::Availabe;
FString Activity = FString("My New Activity");
FRegistry::Lobby.Connect();
FRegistry::Lobby.SendSetPresenceStatus(Availability, Activity);
}));
FString UserActivity = TEXT("Playing Game");
AccelByte::FRegistry::Lobby.SendSetPresenceStatus(Availability::Busy, UserActivity);
UserStatus status = UserStatus.Availabe;
string activity = "My New Activity";
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().SetUserStatus(status, activity, result =>
{
if (result.IsError)
{
// Do something if SetUserStatus has an error
Debug.Log($"Error SetUserStatus, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if SetUserStatus has been successful
}
});
View a Friend’s Status
This allows the player’s friends to see when the player is online and what they are doing.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetUserPresenceNotifDelegate(AccelByte::Api::Lobby::FFriendStatusNotif::CreateLambda([](const FAccelByteModelsUsersPresenceNotice& Result)
{
// Do something if UserPresenceNotifDelegate has been successful
}));
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().FriendsStatusChanged += result =>
{
if (result.IsError)
{
// Do something if FriendsStatusChanged has an error
Debug.Log($"Error FriendsStatusChanged, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if FriendsStatusChanged has been successful
}
};
Get a List of Friends’ Statuses
Players can also see a list of all of their friends’ statuses.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetGetOnlineFriendsPresenceResponseDelegate(AccelByte::Api::Lobby::FGetAllFriendsStatusResponse::CreateLambda([](const FAccelByteModelsGetOnlineUsersResponse& Result)
{
if (Result.Code == "0")
{
// Do something if GetOnlineFriendsPresenceResponseDelegate has been successful
}
else
{
// Do something if GetOnlineFriendsPresenceResponseDelegate has an error
}
}));
FRegistry::Lobby.SendGetOnlineFriendPresenceRequest();
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().ListFriendsStatus(result =>
{
if (result.IsError)
{
// Do something if ListFriendsStatus has an error
Debug.Log($"Error ListFriendsStatus, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if ListFriendsStatus has been successful
}
});
Bulk Friends Presence
Retrieve player’s presence information in bulk. This will also count the number of users based on their presence status, such as online, busy, invisible, or offline. You can also set the countOnly parameter to true to fetch the count without fetching the users’ account data.
- Unreal Engine
- Unity
TArray<FString> UserIds = {FString("12345abcd"), FString("abcd12345")};
bool CountOnly = true;
FRegistry::Lobby.Connect();
FRegistry::Lobby.BulkGetUserPresence(UserIds, THandler<FAccelByteModelsBulkUserStatusNotif>::CreateLambda([](const FAccelByteModelsBulkUserStatusNotif& Result)
{
// Do something if BulkGetUserPresence has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if BulkGetUserPresence has an error
UE_LOG(LogTemp, Log, TEXT("Error BulkGetUserPresence, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}), CountOnly);
string[] userIds = { "12345abcd", "abcd12345" };
bool countOnly = true;
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().BulkGetUserPresence(userIds, result =>
{
if (result.IsError)
{
// Do something if BulkGetUserPresence has an error
Debug.Log($"Error BulkGetUserPresence, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if BulkGetUserPresence has been successful
}
}, countOnly);