Class InMemoryJoinCodeService

Namespace
Unity.Multiplayer.Core

An IJoinCodeService that keeps its codes in this process: for tests, local play and as the reference behaviour the networked implementations match. Thread-safe.

public sealed class InMemoryJoinCodeService : IJoinCodeService, IDisposable
Inheritance
InMemoryJoinCodeService
Implements
Inherited Members

Remarks

Codes never expire here; they live until RevokeAsync(JoinCode, CancellationToken).

Constructors

InMemoryJoinCodeService()

Mints DefaultDataLength-character codes from a cryptographic RNG.

public InMemoryJoinCodeService()

InMemoryJoinCodeService(int, RandomNumberGenerator)

Mints codes with dataLength data characters from rng (a cryptographic RNG when null; the service does not dispose one it was given).

public InMemoryJoinCodeService(int dataLength, RandomNumberGenerator rng)

Parameters

dataLength int
rng RandomNumberGenerator

Exceptions

ArgumentOutOfRangeException

dataLength is out of range.

Properties

Count

How many codes are live.

public int Count { get; }

Property Value

int

Methods

Dispose()

Disposes the RNG if this service created it.

public void Dispose()

PublishAsync(JoinTarget, CancellationToken)

Publishes target and returns the code players join with.

public Task<JoinCode> PublishAsync(JoinTarget target, CancellationToken cancellationToken = default)

Parameters

target JoinTarget
cancellationToken CancellationToken

Returns

Task<JoinCode>

Exceptions

ArgumentNullException

target is null.

NotSupportedException

This service cannot publish that Kind.

ResolveAsync(JoinCode, CancellationToken)

The target code leads to, or null when it is unknown, revoked or expired.

public Task<JoinTarget> ResolveAsync(JoinCode code, CancellationToken cancellationToken = default)

Parameters

code JoinCode
cancellationToken CancellationToken

Returns

Task<JoinTarget>

RevokeAsync(JoinCode, CancellationToken)

Withdraws code so it no longer resolves. True when it was live.

public Task<bool> RevokeAsync(JoinCode code, CancellationToken cancellationToken = default)

Parameters

code JoinCode
cancellationToken CancellationToken

Returns

Task<bool>