Limiting the maximum number of players
Netcode for GameObjects provides a way to customize the connection approval process that can reject incoming connections based on any number of user-specific reasons.
The code below shows an example of an over-capacity check that would prevent more than a certain pre-defined number of players from connecting.
if( m_Portal.NetManager.ConnectedClientsIds.Count >= CharSelectData.k_MaxLobbyPlayers )
{
return ConnectStatus.ServerFull;
}
[!NOTE] In connection approval delegate, Netcode for GameObjects doesn't support sending anything more than a Boolean back.
When using Relay, ensure the maximum number of peer connections allowed by the host satisfies the logic implemented in the connection approval delegate.