multiplayer-community-contributions icon indicating copy to clipboard operation
multiplayer-community-contributions copied to clipboard

Facepunch Transport - Detect Host losing internet connection

Open WaGi-Coding opened this issue 2 years ago • 0 comments

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");
        }
    }
}

WaGi-Coding avatar Apr 25 '23 02:04 WaGi-Coding