mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
NetworkClient.Disconnect: cleanup code moved into OnTransportDisconnected
This commit is contained in:
parent
4de0d4a28a
commit
a056072aec
@ -205,36 +205,11 @@ public static void ConnectLocalServer()
|
||||
|
||||
// disconnect //////////////////////////////////////////////////////////
|
||||
/// <summary>Disconnect from server.</summary>
|
||||
// Simply call NetworkConnection.Disconnect -> Transport.Disconnect.
|
||||
// Cleanup happens in OnTransportDisconnected!
|
||||
public static void Disconnect()
|
||||
{
|
||||
connectState = ConnectState.Disconnected;
|
||||
ready = false;
|
||||
|
||||
// local or remote connection?
|
||||
if (isLocalClient)
|
||||
{
|
||||
if (isConnected)
|
||||
{
|
||||
// call client OnDisconnected with connection to server
|
||||
// => previously we used to send a DisconnectMessage to
|
||||
// NetworkServer.localConnection. this would queue the
|
||||
// message until NetworkClient.Update processes it.
|
||||
// => invoking the client's OnDisconnected event directly
|
||||
// here makes tests fail. so let's do it exactly the same
|
||||
// order as before by queueing the event for next Update!
|
||||
//OnDisconnectedEvent?.Invoke(connection);
|
||||
((LocalConnectionToServer)connection).QueueDisconnectedEvent();
|
||||
}
|
||||
NetworkServer.RemoveLocalConnection();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (connection != null)
|
||||
{
|
||||
connection.Disconnect();
|
||||
connection = null;
|
||||
}
|
||||
}
|
||||
connection?.Disconnect();
|
||||
}
|
||||
|
||||
/// <summary>Disconnect host mode.</summary>
|
||||
@ -291,6 +266,36 @@ static void OnTransportDisconnected()
|
||||
connectState = ConnectState.Disconnected;
|
||||
ready = false;
|
||||
|
||||
// this was in Disconnect() before.
|
||||
// but it should happen after truly disconnecting here.
|
||||
|
||||
// local or remote connection?
|
||||
if (isLocalClient)
|
||||
{
|
||||
// TODO move into LocalConnection.Disconnect
|
||||
if (isConnected)
|
||||
{
|
||||
// call client OnDisconnected with connection to server
|
||||
// => previously we used to send a DisconnectMessage to
|
||||
// NetworkServer.localConnection. this would queue the
|
||||
// message until NetworkClient.Update processes it.
|
||||
// => invoking the client's OnDisconnected event directly
|
||||
// here makes tests fail. so let's do it exactly the same
|
||||
// order as before by queueing the event for next Update!
|
||||
//OnDisconnectedEvent?.Invoke(connection);
|
||||
((LocalConnectionToServer)connection).QueueDisconnectedEvent();
|
||||
}
|
||||
NetworkServer.RemoveLocalConnection();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (connection != null)
|
||||
{
|
||||
connection.Disconnect();
|
||||
connection = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (connection != null) OnDisconnectedEvent?.Invoke();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user