NetworkClient.OnTransportDisconnected: local connection cleanup code moved into LocalConnection Disconnect

This commit is contained in:
vis2k 2021-05-11 11:42:03 +08:00
parent 73df46e2b0
commit 3afad21de9
2 changed files with 13 additions and 22 deletions

View File

@ -118,6 +118,19 @@ public override void Disconnect()
{
connectionToClient.DisconnectInternal();
DisconnectInternal();
// THIS WAS PREVIOUSLY IN NETWORKCLIENT.DISCONNECT:
// 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);
QueueDisconnectedEvent();
NetworkServer.RemoveLocalConnection();
}
// true because local connections never timeout

View File

@ -266,28 +266,6 @@ static void OnTransportDisconnected()
connectState = ConnectState.Disconnected;
ready = false;
// this was in Disconnect() before.
// but it should happen after truly disconnecting here.
// local 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();
}
// call OnDisconnected event. NetworkManager hooks into it.
OnDisconnectedEvent?.Invoke();