Hello everyone!
First, thanks for your help on the matter.
I’m currently working with Unet (and learning a lot), I have came to face a problem.
Let’s put it this way. The game I’m building can have up to 4 players in a scene.
The game allows full controls over what should controls each of the 4 players:
• P1 can be controlled locally by a keyboard or a controller.
• P2 can be controlled locally by a keyboard or a controller or by an AI (controlled on the host, so locally if on the host PC) or a remote player’s client via LAN.
• P3 can be controlled locally by a keyboard or a controller or by an AI (controlled on the host, so locally if on the host PC) or a remote player’s client via LAN.
• P4 can be controlled locally by a keyboard or a controller or by an AI (controlled on the host, so locally if on the host PC) or a remote player’s client via LAN.
Everything seems to works fine. Controls are responding both locally and over the network whenever applicable, animation runs smoothly, but I’m still stuck with one little pickle.
It’s kinda hard to explain and whenever I looked online, there’s too much similar terms polluting the results for >20 pages. It’s a real nightmare to read every small bit just in case it cover the things I’m looking for. (I have done it for the last 2 days with barely no break except for the basic living needs). So, please, bear with me if I’m not clear enough.
As I’m building the game with, in mind, its online features as the base of the system with an Host based connection (meaning the host is both a client and a server), the obvious way of managing the single player or local multiplayer should, in theory, be to run the application as a client + server like when online, but limiting the number of client able to connect to the server to only be the host’s. This is how many coop/PvE based games do it.
Now, this is where the NetworkManager seems to fails for some reason. Whenever you set the maximum connection (through the inspector) to the minimum (in “Advanced Configuration”), the number can’t be below 1. Normally, you might guess that this is because the host has to be counted in… but it seems that it’s not the case and that is a minimum of 1 remote client (meaning not counting the host).
This brings me to wonder how can we limit the number of client that can remotely connect to the host to none?
So, let’s say the player start “host” a game. As of the moment, he got no remote friend to play with. So he wish to start playing alone against AI (or a relative play with him on the same client/application as I made the game controls system in a way that such thing is possible and all.)
If it was to about limiting the maximum amount of remote clients that can connect, that would be quite simple as I would simply limit the maximum amount of connected client to the current amount, but for some reason NetworkManager doesn’t accept something like no connection except for the host as it always leaves 1 slot opened.
I don’t think I got to explain how much it can break a game when a 5th player join a game/match that already has not open slots, right? (So, a 5th player join a hosted game which has already the host and 3 AI. The host might not want anyone to join his game, but for some reason someone is still able to join.)
Does anyone knows how to fix this kind of problem? Is there a way to automatically reject any incoming connections attempts from a host’s server when it only has the host connected to it?
I have read the whole NetworkManager documentation and the only kind of thing I found is related to closing the server (which obviously doesn’t work as I need the server to run, but only allow the host’s client to connect to it.)
Currently, the only thing that comes to my mind is to disconnect any new players that connect automatically. (So the 5th player connect and the server automatically call a disconnect function with a warning notice that the game is full.) I wonders if it’s possible to simply STOP any connection from coming in even if the host’s client is “alone” on its own server.
Thanks in advance for any feedback on the matter!