Limiting the maximum number of players (NetworkDriver)

Hello Everyone,

I want to make a connection approval process that can reject incoming connections based on any number of connected players. How can I limit the number of players (Clients) connecting the game (Server)? Does network driver count the connected players or should I do my own counter on server side? How can I use ServerClientCount in Bootstrap (ClientServerBootstrap.WorldCounts.Data.serverWorldsClientServerBootstrap.WorldCounts.Data.serverWorlds)

public static void RegisterServerDriver(World world, ref NetworkDriverStore driverStore, NetDebug netDebug, ref FixedString4096Bytes certificate, ref FixedString4096Bytes privateKey, int playerCount = 0
        {
            var settings = GetNetworkServerSettings(playerCount: playerCount);
            settings = settings.WithSecureServerParameters(certificate: ref certificate, privateKey: ref privateKey);
            RegisterServerDriver(world, ref driverStore, netDebug, settings);
        }

Thanks in advance.

Hey OrientedPain!

Unfortunately there is currently no way to limit player count via UTP directly. You’ll need to:

  • Accept the connection.
  • Immediately close it again (via the NetworkConnection entity) based on connected player count. Optionally after sending an RPC containing a reason for the server kick.

Relatedly, you may find the following thread valuable, depending on the kind of security you need for your game:

2 Likes

Thank you so much NiKi, you’re awesome as usual :slight_smile:

1 Like