The easiest way to disconnect a client without errors seems to be:
myNetworkLobbyManager.StopHost(); // Not sure if this is the best way, but hey
However, disconnecting a server using StopHost() works, BUT for the next 30 seconds, clients can still join. In fact, you can even rejoin your OWN game, then the match will crash 30 seconds later!
That said, what is the proper way to do it, preferably using HLAPI?
I’d love a @ dev’s opinion since there are countless versions of this exact thread – all unanswered and left lingering what the best way is.
My current experiment (works for client, not for server):
// : NetworkLobbyManager
if (this.lobbySlots[mySlot].isServer) // Is slot ALWAYS 0 for localPlayer?
Network.Disconnect(); // Testing..[/COLOR][B] [COLOR=#ff0000](EDIT: Failed)[/COLOR][/B][/COLOR][/COLOR][/COLOR]
[COLOR=#000000][COLOR=#000000][COLOR=#000000][COLOR=#000000]else
this.StopHost(); // Works fine for client, cleans up well
What does NOT work - usually resulting in the following err (from a NetworkLobbyManager script):
A connection has already been set as ready. There can only be one.
ClientScene::AddPlayer: playerControllerId of 0 already in use.
- Network.Disconnect()
- this.StopHost()
- this.StopServer() // Why wouldn’t this work…? It only makes sense
Thoughts:
- One of the above probably works without HLAPI, but HLAPI does “clean up” for you. It’s probably some order-of-operations thing where a HLAPI callback is being triggered and attempting to re-enter the lobby BEFORE things are fully disconnected. Unfortunately, again, this is something that we’d be able to code in 10 seconds if it was actually documented in the API docs (cough, @ ).