Class ConnectionPayload

Namespace
Unity.Multiplayer.Core

What a client sends with its connection request: the game version and protocol hash it was built with, the player token that identifies it across reconnects, and the name and colour it wants to play as. ConnectionPayloadCodec turns it into bytes; ConnectionApprovalValidator decides whether the server lets it in.

public sealed class ConnectionPayload
Inheritance
ConnectionPayload
Inherited Members

Remarks

Immutable. The constructor accepts anything so a decoder can build an instance and then report every problem from Validate(); Encode(ConnectionPayload) refuses an invalid one.

Constructors

ConnectionPayload(string, ProtocolHash, string, string, PlayerColor)

Builds a payload; call Validate() to check it.

public ConnectionPayload(string gameVersion, ProtocolHash protocolHash, string playerToken, string displayName, PlayerColor color)

Parameters

gameVersion string

The client's game version; must equal the server's.

protocolHash ProtocolHash

The client's protocol hash; must equal the server's.

playerToken string

An opaque, stable identifier for this player (for example a GUID kept in local storage). The server uses it to give a reconnecting player its seat back and to check bans. Printable ASCII, no spaces.

displayName string

The name other players see.

color PlayerColor

The colour the player picked.

ConnectionPayload(string, ProtocolHash, string, string, PlayerColor, string)

Builds a payload carrying the server password the player gave; call Validate() to check it.

public ConnectionPayload(string gameVersion, ProtocolHash protocolHash, string playerToken, string displayName, PlayerColor color, string password)

Parameters

gameVersion string

The client's game version; must equal the server's.

protocolHash ProtocolHash

The client's protocol hash; must equal the server's.

playerToken string

The opaque, stable identifier for this player.

displayName string

The name other players see.

color PlayerColor

The colour the player picked.

password string

The server password, or null / empty for none (Password).

Fields

MaxDisplayNameLength

Longest accepted DisplayName, in characters.

public const int MaxDisplayNameLength = 32

Field Value

int

MaxGameVersionLength

Longest accepted GameVersion, in characters.

public const int MaxGameVersionLength = 64

Field Value

int

MaxPasswordLength

Longest accepted Password, in characters.

public const int MaxPasswordLength = 64

Field Value

int

MaxPlayerTokenLength

Longest accepted PlayerToken, in characters.

public const int MaxPlayerTokenLength = 128

Field Value

int

Properties

Color

The colour the player picked.

public PlayerColor Color { get; }

Property Value

PlayerColor

DisplayName

The name other players see.

public string DisplayName { get; }

Property Value

string

GameVersion

The client's game version.

public string GameVersion { get; }

Property Value

string

IsValid

True when Validate() finds no problems.

public bool IsValid { get; }

Property Value

bool

Password

The server password the player gave; empty for none. Never included in ToString().

public string Password { get; }

Property Value

string

PlayerToken

The opaque, stable identifier for this player.

public string PlayerToken { get; }

Property Value

string

ProtocolHash

The client's protocol hash.

public ProtocolHash ProtocolHash { get; }

Property Value

ProtocolHash

Methods

EnsureValid()

Throws ArgumentException listing every problem if the payload is invalid.

public void EnsureValid()

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

Validate()

Lists every problem with this payload; an empty list means it is valid.

public IReadOnlyList<string> Validate()

Returns

IReadOnlyList<string>