> For the complete documentation index, see [llms.txt](https://docs.coherence.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coherence.io/2.4/hosting/coherence-cloud/authentication-service-player-accounts-1.md).

# Blocking Service

The **Blocking Service** can be used to block (and unblock) [Player Accounts](/2.4/hosting/coherence-cloud/authentication-service-player-accounts.md), and acquire a list of all blocked player account IDs.

The service also supports merging in platform-specific block lists into its results via the `IBlockListProvider` interface.

You can access the **Blocking Service** via **CloudService**, which can be acquired via the [Services](https://unityapi.coherence.io/docs/v2.2.0/api/Coherence.Cloud.PlayerAccount.Services.html#Coherence_Cloud_PlayerAccount_Services) property of a Player Account.

{% hint style="info" %}
You must be logged into the coherence Cloud to use this service. Read more about authentication on the [Player Accounts](/2.4/hosting/coherence-cloud/authentication-service-player-accounts.md) page.
{% endhint %}

## **Blocking a Player**

You can use **BlockingService.BlockPlayerAsync** to block a player account with a particular ID.

The blocked player will be prevented from entering the same room or lobby as the blocking player in the future.

```csharp
using Coherence.Cloud;
using UnityEngine;

class BlockPlayerExample : MonoBehaviour
{
    public string playerAccountId;

    async void Start()
    {
        // Wait until a player account has logged in to coherence Cloud.
        // The CoherenceCloudLogin component can be used for this.
        PlayerAccount playerAccount = await PlayerAccount.GetMainAsync();

        // Block the player account with the given id.
        // The blocked player is prevented from entering the same room or lobby as the local player in the future.
        var blocking = playerAccount.Services.Blocking;
        await blocking.BlockPlayerAsync(playerAccountId);
    }
}
```

Note that a blocked player is not automatically kicked from any lobby or room the local player is also currently in.

## **Unblocking a Player**

You can use **BlockingService.UnblockPlayerAsync** to remove a block against a player previously requested using **BlockPlayerAsync**.

```csharp
// Remove the block against the player account with the given id.
await blocking.UnblockPlayerAsync(playerAccountId);
```

Note that this only removes the block from coherence Cloud internally. If the block also exists in the platform specific block list, you'll need use the platform's own API to remove the block from there as well.

## Getting List of Blocked Players

You can use **BlockingService.GetBlockedPlayersAsync** to get a list of all player accounts that the local player has blocked.

```csharp
using Coherence.Cloud;
using Coherence.Runtime;
using UnityEngine;

class GetBlockedPlayersExample : MonoBehaviour
{
    // Gets populated with all player accounts blocked by the local player.
    public BlockedPlayers blockedPlayers;

    async void Start()
    {
        // Wait until a player account has logged in to coherence Cloud.
        // The CoherenceCloudLogin component can be used for this.
        PlayerAccount playerAccount = await PlayerAccount.GetMainAsync();

        // Get all player accounts that the local player has blocked.
        var blocking = playerAccount.Services.Blocking;
        blockedPlayers = await blocking.GetBlockedPlayersAsync();

        // Print the list to the console:
        Debug.Log($"Blocked players: {string.Join(", ", blockedPlayers)}");

        // Print the list to the Console again whenever its contents change:
        blockedPlayers.OnChanged += () => Debug.Log($"Blocked players: {string.Join(", ", blockedPlayers)}");
    }
}

```

You can also get notified whenever the player blocks or unblocks players by subscribing to the `PlayerAccountIds.OnChanged` event on the object that the GetBlockedPlayersAsync method returns.

## Block List Providers

You can create one or more implementations of the `IBlockListProvider` interface to merge platform-native lists of blocked player IDs into GetBlockedPlayersAsync results.

```csharp
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Coherence.Runtime;

class PlayStationBlockListProvider : IBlockListProvider
{
    public BlockListSource Source => BlockListSource.PlayStation;

    // Allow logging in to coherence Cloud to complete without having
    // to first wait for the blocked ids to get acquired from this provider.
    public bool RequiredForLogIn => false;

    // Returns the PSN Account IDs the local user has blocked
    public async Task<IReadOnlyList<string>> GetOutboundBlockedIdsAsync(CancellationToken cancellationToken = default)
    {
        var ids = new List<string>();
        int? offset = 0;
        while (offset.HasValue)
        {
            var page = await PlayStationManager.GetBlockingUsersAsync(offset.Value, limit: 2000, cancellationToken);
            ids.AddRange(page.BlockedIds);
            offset = page.NextOffset;
        }

        return ids;
    }
}
```

coherence will automatically find all concrete types that implement the interface and acquire the blocked ID lists using them.

{% hint style="info" %}
Game teams shipping on console platforms (PlayStation, Xbox or Switch) must create a block list provider implementation for each platform to pass verification.
{% endhint %}
