mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
fix: NetworkManager - handle StopClient in Host mode
This commit is contained in:
parent
5e0b450f87
commit
a83379fe17
@ -1192,7 +1192,9 @@ void OnClientAuthenticated()
|
|||||||
void OnClientDisconnectInternal()
|
void OnClientDisconnectInternal()
|
||||||
{
|
{
|
||||||
//Debug.Log("NetworkManager.OnClientDisconnectInternal");
|
//Debug.Log("NetworkManager.OnClientDisconnectInternal");
|
||||||
if (mode == NetworkManagerMode.Offline)
|
|
||||||
|
// Only let this run once. StopClient in Host mode changes to ServerOnly
|
||||||
|
if (mode == NetworkManagerMode.ServerOnly || mode == NetworkManagerMode.Offline)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// user callback
|
// user callback
|
||||||
@ -1214,12 +1216,14 @@ void OnClientDisconnectInternal()
|
|||||||
&& SceneManager.GetActiveScene().path != offlineScene)
|
&& SceneManager.GetActiveScene().path != offlineScene)
|
||||||
SceneManager.MoveGameObjectToScene(gameObject, SceneManager.GetActiveScene());
|
SceneManager.MoveGameObjectToScene(gameObject, SceneManager.GetActiveScene());
|
||||||
|
|
||||||
// set offline mode BEFORE changing scene so that FinishStartScene
|
// set mode BEFORE changing scene so FinishStartScene doesn't re-initialize anything.
|
||||||
// doesn't think we need initialize anything.
|
// set mode BEFORE NetworkClient.Disconnect so StopClient only runs once.
|
||||||
// set offline mode BEFORE NetworkClient.Disconnect so StopClient
|
// set mode BEFORE OnStopClient so StopClient only runs once.
|
||||||
// only runs once.
|
// If we got here from StopClient in Host mode, change to ServerOnly.
|
||||||
// set offline mode BEFORE OnStopClient so StopClient
|
// - If StopHost was called, StopServer will put us in Offline mode.
|
||||||
// only runs once.
|
if (mode == NetworkManagerMode.Host)
|
||||||
|
mode = NetworkManagerMode.ServerOnly;
|
||||||
|
else
|
||||||
mode = NetworkManagerMode.Offline;
|
mode = NetworkManagerMode.Offline;
|
||||||
|
|
||||||
//Debug.Log("NetworkManager StopClient");
|
//Debug.Log("NetworkManager StopClient");
|
||||||
@ -1228,7 +1232,10 @@ void OnClientDisconnectInternal()
|
|||||||
// shutdown client
|
// shutdown client
|
||||||
NetworkClient.Shutdown();
|
NetworkClient.Shutdown();
|
||||||
|
|
||||||
// If this is the host player, StopServer will already be changing scenes.
|
// Exit here if we're now in ServerOnly mode (StopClient called in Host mode).
|
||||||
|
if (mode == NetworkManagerMode.ServerOnly) return;
|
||||||
|
|
||||||
|
// If StopHost called in Host mode, StopServer will change scenes after this.
|
||||||
// Check loadingSceneAsync to ensure we don't double-invoke the scene change.
|
// Check loadingSceneAsync to ensure we don't double-invoke the scene change.
|
||||||
// Check if NetworkServer.active because we can get here via Disconnect before server has started to change scenes.
|
// Check if NetworkServer.active because we can get here via Disconnect before server has started to change scenes.
|
||||||
if (!string.IsNullOrWhiteSpace(offlineScene) && !Utils.IsSceneActive(offlineScene) && loadingSceneAsync == null && !NetworkServer.active)
|
if (!string.IsNullOrWhiteSpace(offlineScene) && !Utils.IsSceneActive(offlineScene) && loadingSceneAsync == null && !NetworkServer.active)
|
||||||
|
Loading…
Reference in New Issue
Block a user