Friend Service Tasks #
Common objectives you can achieve using the Friend Service include:
- Initialize the Friend SDK (Required)
- Configure max pending sent/received invites
- Send a friend invite
- Accept or decline a friend invite
- Invite a friend to join your party (obtain the friend’s Player ID, and then send a party invite using that value)
- Block or unblock accounts
- Disable or enable incoming invites
- View friend list and invite data
- Remove a friend from your friend list
Initialize the Friend SDK (Required) #
Before you can issue any Friend service calls using the Friend API, you must initialize the service using the Friend API Initialize
method. This step will synchronize friend states between the SDK and the Pragma backend.
Initialize()
can only be called after login. Upon logout, the service is un-initialized and theOn*
action-handlers are unbound. You must callinitialize()
on the service when you log back in.
Player->FriendApi().Initialize(
const FOnCompleteDelegate& OnComplete
);
Player.FriendApi.Initialize(
CompleteDelegate onComplete
);
The Initialize
method triggers the OnChanged
events, providing you with a list of friends and invites. After you receive a successful response, you can begin using the Friend service API.
While the Pragma SDK constantly attempts to stay in sync with the Pragma Engine backend, there may be instances where you want to explicitly force the Friend API to sync with the backend data. To forcibly synchronize the client’s state with the platform, call the FriendApi ForceSync
function.
Related events:
Related errors:
Configure maximum pending sent or received invites #
Developers can set a maximum number of sent or received invites a player can have in a pending state at one time. When a pending sent or received invite is accepted, rejected, or canceled, the player can again send or receive invites.
serviceConfigs:
FriendServiceConfig:
...
Send a friend invite #
A player can send an invite to another player using the player’s social ID or display name. Social IDs and display names may be visible in game instances, on leaderboards, or communicated through methods outside of Pragma, such as via voice chat or direct message. Developers can access the SocialId
and DisplayName
via the Party Player object. Pragma recommends sending invites by socialId if possible because display names can easily change. However, display names may be preferable if manually typing in a value.
When called, SendFriendInviteByDisplayName
and SendFriendInviteBySocialId
add a pending sent invite to the inviter’s friend list, and a pending received invite to the invitee’s friend list.
Players cannot send invites to players if they are on the player’s blocklist. Similarly, you cannot send a friend invite to an account on your blocklist. Doing so will result in a Friend_InviteeIsBlocked
error.
If a player’s number of pending sent invites is at its max, the oldest pending sent friend invite is removed to make room for the new one. If a player’s received invites list is full, the inviter will receive a Friend_InviteeReceivedInvitesFull
error.
Invites do not expire.
Send a friend invite by social ID #
To send a friend invite using the invitee’s social ID, use the Friend API’s SendFriendInviteBySocialId
method.
Player->FriendApi().SendFriendInviteBySocialId(
const FString& SocialId,
const FOnCompleteDelegate& OnComplete
);
Player.FriendApi.SendFriendInviteBySocialId(
PragmaId socialId,
CompleteDelegate onComplete
);
{
"requestId": 1,
"type": "FriendRpc.SendFriendInviteBySocialIdV1Request",
"payload": {
"inviteeSocialId": "9c82f3d5-5857-4f93-a07f-f6bb38fd9aba"
}
}
Send a friend invite by display name #
To send a friend invite using the invitee’s display name, use the Friend API’s SendFriendInviteByDisplayName
method.
Player->FriendApi().SendFriendInviteByDisplayName(
const FPragma_Account_DisplayName& DisplayName,
const FOnCompleteDelegate& OnComplete
);
Player.FriendApi.SendFriendInviteByDisplayName(
DisplayName displayName,
CompleteDelegate onComplete
);
{
"requestId": 1,
"type": "FriendRpc.SendFriendInviteV1Request",
"payload": {
"inviteeDisplayName": {
"displayName": "test02",
"discriminator": "9165"
}
}
}
Related events:
Related errors:
- Friend_BlockedByInvitee
- Friend_InviteeReceivedInvitesFull
- Friend_SocialIdentityNotFound
- Friend_InviteeIsBlocked
- Friend_SelfOperationNotAllowed
Accept a friend invite #
To accept a friend invite, use the Friend API’s AcceptFriendInvite
method with the inviter’s socialId
. When accepted, the inviter and invitee are added to each other’s friend list.
Player->FriendApi().AcceptFriendInvite(
const FString& InviterSocialId,
const FOnCompleteDelegate& OnComplete
);
Player.FriendApi.AcceptFriendInvite(
PragmaId inviterSocialId,
CompleteDelegate onComplete
);
{
"requestId": 1,
"type": "FriendRpc.RespondToFriendInviteV1Request",
"payload": {
"inviterSocialId": "9c82f3d5-5857-4f93-a07f-f6bb38fd9aba",
"acceptInvite": true
}
}
To view pending friend invites, use GetReceivedInvites
.
Related events:
Related errors:
Decline a friend invite #
To decline a friend invite, use the Friend API’s DeclineFriendInvite
with the inviter’s social ID.
Player->FriendApi().DeclineFriendInvite(
const FString& InviterSocialId,
const FOnCompleteDelegate& OnComplete
);
Player.FriendApi.DeclineFriendInvite(
PragmaId inviterSocialId,
CompleteDelegate onComplete
);
{
"requestId": 1,
"type": "FriendRpc.RespondToFriendInviteV1Request",
"payload": {
"inviterSocialId": "9c82f3d5-5857-4f93-a07f-f6bb38fd9aba",
"acceptInvite": false
}
}
To view pending friend invites, use GetReceivedInvites
.
Related events:
Related errors:
Block or unblock accounts #
Developers can allow players to block and unblock friend invites from a specific account.
Blocking invites works on the account level. Thus, blocking another player prevents them from sending invites across all game shards.
Block single account #
The Friend API’s Block
allows a player to block friend invites sent by a specific account. When a player blocks an account, the specified account, identified by the socialId
, is added to the blocker’s block list. Any pending invitations from the blocked account are automatically deleted. If the players are friends, Pragma Engine removes each player from the others’ friend list before blocking.
Player->FriendApi().Block(
const FString& SocialId, c
onst FOnCompleteDelegate& OnComplete
);
Player.FriendApi.Block(
PragmaId socialId,
CompleteDelegate onComplete
);
If a blocked player attempts to send a friend invite, they receive the Friend_BlockedByInvitee
error.
Unblock single account #
The Unblock
method allows a player to unblock an account on their block list. The specified account, identified by the socialId
, is removed from the issuing player’s block list and can send them friend invites. If the blocked player was a friend before being blocked, the friend status is not restored.
Player->FriendApi().Unblock(
const FString& SocialId,
const FOnCompleteDelegate& OnComplete
);
Player.FriendApi.Unblock(
PragmaId socialId,
CompleteDelegate onComplete
);
View block list #
The GetBlockedList
method returns all accounts on a player’s block list.
Unreal:
Player->FriendApi().GetBlockedList();
Related events
Related errors:
Disable or enable all incoming friend invites #
Developers can allow players to disable or enable all incoming invites from any account using the DisableIncomingFriendInvites
and EnableIncomingFriendInvites
methods. By default, all players can receive invites.
Disabling or enabling incoming invites does not add or remove accounts from a player’s block list.
To disable all incoming invites, use DisableIncomingFriendInvites
. Players who attempt to send friend invites to accounts that have incoming invites disabled will receive the Friend_InviteeDisabledInvites
error.
Player->FriendApi().DisableIncomingFriendInvites(
const FOnCompleteDelegate& OnComplete
);
Player.FriendApi.DisableIncomingFriendInvites(
CompleteDelegate onComplete
);
To enable all incoming invites, use EnableIncomingFriendInvites
:
Player->FriendApi().EnableIncomingFriendInvites(
const FOnCompleteDelegate& OnComplete
);
Player.FriendApi.EnableIncomingFriendInvites(
CompleteDelegate onComplete
);
Related events
Related errors:
Remove a friend #
To remove a player from your friend list, use the Friend API’s RemoveFriend
with the player’s social ID. This call removes each player from the other player’s friend list.
Player->FriendApi().RemoveFriend(
const FString& SocialId,
const FOnCompleteDelegate& OnComplete
);
Player.FriendApi.RemoveFriend(
PragmaId socialId,
CompleteDelegate onComplete
);
{
"requestId": 1,
"type": "FriendRpc.RemoveFriendV1Request",
"payload": {
"friendSocialId": "9c82f3d5-5857-4f93-a07f-f6bb38fd9aba"
}
}
Related events:
Related errors: