Interface IJoinCodeService
- Namespace
- Unity.Multiplayer.Core
Turns a server's JoinTarget into a short JoinCode players can type, and back. RFC 0001 has two implementations in the adapter (UM-T13): Unity Relay (the default for listen servers, since it gets through NAT) and the self-hosted rendezvous service (the default for dedicated servers). InMemoryJoinCodeService is the in-process one.
public interface IJoinCodeService
Remarks
Contract every implementation keeps:
- PublishAsync(JoinTarget, CancellationToken) returns a non-empty code that ResolveAsync(JoinCode, CancellationToken) maps back to an equal target until it is revoked or expires.
- Codes are unique among live publications: two live publications never share a code.
- ResolveAsync(JoinCode, CancellationToken) returns null (it does not throw) for a code that was never published, was revoked or expired. It throws only when the service itself cannot be reached.
- RevokeAsync(JoinCode, CancellationToken) is idempotent: revoking an unknown or already revoked code returns false and changes nothing.
- A code is a JoinCode, so it has already passed the format check; parse player input with TryParse(string, out JoinCodeParseResult) first.
Methods
PublishAsync(JoinTarget, CancellationToken)
Publishes target and returns the code players join with.
Task<JoinCode> PublishAsync(JoinTarget target, CancellationToken cancellationToken = default)
Parameters
targetJoinTargetcancellationTokenCancellationToken
Returns
Exceptions
- ArgumentNullException
targetis 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.
Task<JoinTarget> ResolveAsync(JoinCode code, CancellationToken cancellationToken = default)
Parameters
codeJoinCodecancellationTokenCancellationToken
Returns
RevokeAsync(JoinCode, CancellationToken)
Withdraws code so it no longer resolves. True when it was live.
Task<bool> RevokeAsync(JoinCode code, CancellationToken cancellationToken = default)
Parameters
codeJoinCodecancellationTokenCancellationToken