Class ConnectionApprovalValidator

Namespace
Unity.Multiplayer.Core

The server's connection-approval rule, engine-free so it is tested here and merely called by the NGO adapter's approval callback (UM-T9).

public sealed class ConnectionApprovalValidator
Inheritance
ConnectionApprovalValidator
Inherited Members

Remarks

Checks run in this order and the first failure decides the reason:

  1. BadPayload: the bytes do not decode to a valid payload (except an unreadable newer format whose game version differs, which is a version mismatch).
  2. VersionMismatch: game versions differ (ordinal, ignoring surrounding whitespace).
  3. ProtocolMismatch: protocol hashes differ.
  4. WrongPassword: the server has a Password and the client's differs.
  5. Banned: the player token is banned.
  6. Full: no seat is free.

Constructors

ConnectionApprovalValidator(string, ProtocolHash, int, IBanList)

Builds the rule for one server.

public ConnectionApprovalValidator(string gameVersion, ProtocolHash protocolHash, int maxPlayers, IBanList banList = null)

Parameters

gameVersion string

The server's game version.

protocolHash ProtocolHash

The server's protocol hash (from FromAssemblies(params Assembly[])).

maxPlayers int

Seats, the host's own player included.

banList IBanList

Bans to enforce; null for none.

Exceptions

ArgumentException

gameVersion is empty or maxPlayers is below one.

Properties

BanList

The bans enforced, or null.

public IBanList BanList { get; }

Property Value

IBanList

GameVersion

The server's game version, trimmed.

public string GameVersion { get; }

Property Value

string

MaxPlayers

Seats, the host's own player included.

public int MaxPlayers { get; }

Property Value

int

Password

The password a client must send (Password, compared exactly); null or empty lets anyone in. Set from Password by FromConfig(NetConfig, ProtocolHash, IBanList).

public string Password { get; set; }

Property Value

string

ProtocolHash

The server's protocol hash.

public ProtocolHash ProtocolHash { get; }

Property Value

ProtocolHash

Methods

FromConfig(NetConfig, ProtocolHash, IBanList)

Builds the rule from a server's NetConfig (game version and max players).

public static ConnectionApprovalValidator FromConfig(NetConfig config, ProtocolHash protocolHash, IBanList banList = null)

Parameters

config NetConfig
protocolHash ProtocolHash
banList IBanList

Returns

ConnectionApprovalValidator

Exceptions

ArgumentNullException

config is null.

Validate(byte[], int)

Decides on raw connection data.

public ApprovalDecision Validate(byte[] connectionData, int connectedPlayers)

Parameters

connectionData byte[]

The bytes the client sent (Encode(ConnectionPayload)).

connectedPlayers int

Players already connected, not counting this one.

Returns

ApprovalDecision

Validate(ConnectionPayload, int)

Decides on an already decoded payload.

public ApprovalDecision Validate(ConnectionPayload payload, int connectedPlayers)

Parameters

payload ConnectionPayload

The client's payload; null is a bad payload.

connectedPlayers int

Players already connected, not counting this one.

Returns

ApprovalDecision