Skip to main content

Read the blocked players list

EOS Online Subsystem provides the "blocked players" functionality of the friends interface. It does this by storing the blocked players in Player Data Storage.

Blocking a player currently has no effect at the plugin level; if you want to prevent a blocked player from interacting with a local user, you'll need to enforce this in your game code.

info

In future, we intend to automatically handle the following scenarios for you:

  • Preventing a game client from seeing session results where a blocked player is the host of the listen server.
  • Preventing a game client from connecting to P2P addresses where the address is that of a blocked player.
  • Preventing a game client from seeing parties or lobbies where a blocked player is the leader or member of the lobby or party.
  • Automatically rejecting friend invitations from blocked players.

Reading the blocked players list

Before you can get the list of blocked players, you need to call QueryBlockedPlayers. Before you call QueryBlockedPlayers for the first time, the list of blocked players will be empty. This is similar to how the friends list (ReadFriendsList) operation works.

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 QueryBlockedPlayers:

// You need to store the handle so you can deregister the event listener
// in the callback.
this->QueryBlockedPlayersHandle =
Friends->AddOnQueryBlockedPlayersCompleteDelegate_Handle(FOnQueryBlockedPlayersCompleteDelegate::CreateUObject(
this,
&UMyClass::OnQueryBlockedPlayersComplete));

if (!Friends->QueryBlockedPlayers(*Identity->GetUniquePlayerId(0)))
{
// Call failed to start.
}

// ...

void UMyClass::OnQueryBlockedPlayersComplete(
const FUniqueNetId &UserId,
bool bWasSuccessful,
const FString &Error)
{
IOnlineSubsystem *Subsystem = Online::GetSubsystem(this->GetWorld());
IOnlineFriendsPtr Friends = Subsystem->GetFriendsInterface();
IOnlineIdentityPtr Identity = Subsystem->GetIdentityInterface();

Friends->ClearOnQueryBlockedPlayersCompleteDelegate_Handle(this->QueryBlockedPlayersHandle);

// Check bWasSuccessful; if it's true, you can now call GetBlockedPlayers.
}

Getting the cached blocked players list

Once QueryBlockedPlayers has completed successfully, you can then call GetBlockedPlayers:

TArray<TSharedRef<FOnlineBlockedPlayer>> BlockedPlayers;
if (!Friends->GetBlockedPlayers(*Identity->GetUniquePlayerId(0), BlockedPlayers))
{
return Results;
}
for (const auto &BlockedPlayer : BlockedPlayers)
{
// Access the blocked player in BlockedPlayer.
}

Modifying the blocked players list

Refer to Block and unblock other players on how to modify the blocked players list.