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:
- BadPayload: the bytes do not decode to a valid payload (except an unreadable newer format whose game version differs, which is a version mismatch).
- VersionMismatch: game versions differ (ordinal, ignoring surrounding whitespace).
- ProtocolMismatch: protocol hashes differ.
- WrongPassword: the server has a Password and the client's differs.
- Banned: the player token is banned.
- 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
gameVersionstringThe server's game version.
protocolHashProtocolHashThe server's protocol hash (from FromAssemblies(params Assembly[])).
maxPlayersintSeats, the host's own player included.
banListIBanListBans to enforce; null for none.
Exceptions
- ArgumentException
gameVersionis empty ormaxPlayersis below one.
Properties
BanList
The bans enforced, or null.
public IBanList BanList { get; }
Property Value
GameVersion
The server's game version, trimmed.
public string GameVersion { get; }
Property Value
MaxPlayers
Seats, the host's own player included.
public int MaxPlayers { get; }
Property Value
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
ProtocolHash
The server's protocol hash.
public ProtocolHash ProtocolHash { get; }
Property Value
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
configNetConfigprotocolHashProtocolHashbanListIBanList
Returns
Exceptions
- ArgumentNullException
configis null.
Validate(byte[], int)
Decides on raw connection data.
public ApprovalDecision Validate(byte[] connectionData, int connectedPlayers)
Parameters
connectionDatabyte[]The bytes the client sent (Encode(ConnectionPayload)).
connectedPlayersintPlayers already connected, not counting this one.
Returns
Validate(ConnectionPayload, int)
Decides on an already decoded payload.
public ApprovalDecision Validate(ConnectionPayload payload, int connectedPlayers)
Parameters
payloadConnectionPayloadThe client's payload; null is a bad payload.
connectedPlayersintPlayers already connected, not counting this one.