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
gameVersionstringThe client's game version; must equal the server's.
protocolHashProtocolHashThe client's protocol hash; must equal the server's.
playerTokenstringAn 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.
displayNamestringThe name other players see.
colorPlayerColorThe 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
gameVersionstringThe client's game version; must equal the server's.
protocolHashProtocolHashThe client's protocol hash; must equal the server's.
playerTokenstringThe opaque, stable identifier for this player.
displayNamestringThe name other players see.
colorPlayerColorThe colour the player picked.
passwordstringThe server password, or null / empty for none (Password).
Fields
MaxDisplayNameLength
Longest accepted DisplayName, in characters.
public const int MaxDisplayNameLength = 32
Field Value
MaxGameVersionLength
Longest accepted GameVersion, in characters.
public const int MaxGameVersionLength = 64
Field Value
MaxPasswordLength
Longest accepted Password, in characters.
public const int MaxPasswordLength = 64
Field Value
MaxPlayerTokenLength
Longest accepted PlayerToken, in characters.
public const int MaxPlayerTokenLength = 128
Field Value
Properties
Color
The colour the player picked.
public PlayerColor Color { get; }
Property Value
DisplayName
The name other players see.
public string DisplayName { get; }
Property Value
GameVersion
The client's game version.
public string GameVersion { get; }
Property Value
IsValid
True when Validate() finds no problems.
public bool IsValid { get; }
Property Value
Password
The server password the player gave; empty for none. Never included in ToString().
public string Password { get; }
Property Value
PlayerToken
The opaque, stable identifier for this player.
public string PlayerToken { get; }
Property Value
ProtocolHash
The client's protocol hash.
public ProtocolHash ProtocolHash { get; }
Property Value
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()