Block and unblock other players
EOS Online Framework provides the "blocked players" functionality of the friends interface. You can modify the blocked players list by calling BlockPlayer and UnblockPlayer.
Refer to Read the blocked players list for more information on how the blocked players list works.
APIs for modifying the friends list only impact the cross-platform friends database and will not affect the local platform or Epic Games friends list. This includes actions such as sending and receiving invites, blocking and unblocking players and modifying recent players.
It is not possible to support modifying the local platform's friends list or Epic Games friends list programmatically, as the platform SDKs and EOS SDK do not expose this functionality.
Blocking another player
- C++
- Blueprints
To block another player, first get the online friends and identity interfaces:
#include "OnlineSubsystem.h"
#include "OnlineSubsystemUtils.h"
#include "Interfaces/OnlineFriendsInterface.h"
#include "Interfaces/OnlineIdentityInterface.h"
// ...
IOnlineSubsystem *Subsystem = Online::GetSubsystem(this->GetWorld());
IOnlineFriendsPtr Friends = Subsystem->GetFriendsInterface();
IOnlineIdentityPtr Identity = Subsystem->GetIdentityInterface();
Then, call BlockPlayer:
// You need to store the handle so you can deregister the event listener
// in the callback.
this->BlockPlayerCompleteHandle = Friends->AddOnBlockedPlayerCompleteDelegate_Handle(
0 /* LocalUserNum */,
FOnBlockedPlayerCompleteDelegate::CreateUObject(
this,
&UMyClass::OnBlockPlayerComplete));
if (!Friends->BlockPlayer(
0 /* LocalUserNum */,
TargetUserId /* User ID to block */)
{
// Call failed to start
}
// ...
void UMyClass::OnBlockPlayerComplete(
int32 LocalUserNum,
bool bWasSuccessful,
const FUniqueNetId &UniqueID,
const FString &ListName,
const FString &ErrorStr)
{
IOnlineSubsystem *Subsystem = Online::GetSubsystem(this->GetWorld());
IOnlineFriendsPtr Friends = Subsystem->GetFriendsInterface();
// NOTE: If you're blocking multiple players in parallel, you'll need to
// capture the original TargetUserId for the BlockPlayer call as a user parameter
// to this callback, and then compare the TargetUserId the event is for with the
// TargetUserId you called BlockPlayer for. You'll also need to store the delegate
// handle (DeleteFriendCompleteHandle) per local user and per target player
// you are blocking.
Friends->ClearOnBlockedPlayerCompleteDelegate_Handle(0, this->BlockPlayerCompleteHandle);
// Check bWasSuccessful; if it's true, the player was blocked.
}
Unblocking a previously blocked player
- C++
- Blueprints
To unblock a player, call UnblockPlayer with the same parameters you called BlockPlayer:
// You need to store the handle so you can deregister the event listener
// in the callback.
this->UnblockPlayerCompleteHandle = Friends->AddOnUnblockedPlayerCompleteDelegate_Handle(
0 /* LocalUserNum */,
FOnUnblockedPlayerCompleteDelegate::CreateUObject(
this,
&UMyClass::OnUnblockPlayerComplete));
if (!Friends->UnblockPlayer(
0 /* LocalUserNum */,
TargetUserId /* User ID to block */)
{
// Call failed to start
}
// ...
void UMyClass::OnUnblockPlayerComplete(
int32 LocalUserNum,
bool bWasSuccessful,
const FUniqueNetId &UniqueID,
const FString &ListName,
const FString &ErrorStr)
{
IOnlineSubsystem *Subsystem = Online::GetSubsystem(this->GetWorld());
IOnlineFriendsPtr Friends = Subsystem->GetFriendsInterface();
// NOTE: If you're unblocking multiple players in parallel, you'll need to
// capture the original TargetUserId for the UnblockPlayer call as a user parameter
// to this callback, and then compare the TargetUserId the event is for with the
// TargetUserId you called UnblockPlayer for. You'll also need to store the delegate
// handle (DeleteFriendCompleteHandle) per local user and per target player
// you are unblocking.
Friends->ClearOnUnblockedPlayerCompleteDelegate_Handle(0, this->BlockPlayerCompleteHandle);
// Check bWasSuccessful; if it's true, the player was unblocked.
}