Unity-Technologies / multiplayer-community-contributions

Community contributions to Unity Multiplayer Networking products and services.
MIT License
415 stars 160 forks source link

Facepunch Transport - Detect Host losing internet connection #216

Open WaGi-Coding opened 1 year ago

WaGi-Coding commented 1 year ago

Hey there, i am using the FacepunchTransport and now i wanted to detect if the host himself lost internet connection and send him back to the main menu if so.

"OnClientDisconnectCallback" does not get called on the host himself when he loses internet.

Thats how i check if the host disconnected for the clients. But how would i do so for the host/server himself?

private void OnClientDisconnectCallback(ulong id) {
    Debug.Log("OnClientDisconnectCallback: " + id.ToString());

    if (IsClient) {
        if (id == 0) { // 0 = host?!
            LobbySaver.instance.currentLobby?.Leave();
            LobbySaver.instance.currentLobby = null;
            NetworkManager.Singleton.Shutdown();

            SceneManager.LoadScene("MainMenu");
        }
    }
}