NetworkServer.DisconnectAllExternalConnections moved into DisconnectAll, because that's what it actually does.

This commit is contained in:
vis2k 2021-05-11 21:51:17 +08:00
parent c44016b049
commit 97b4cb1c0b
2 changed files with 15 additions and 19 deletions

View File

@ -507,16 +507,8 @@ internal static bool GetNetworkIdentity(GameObject go, out NetworkIdentity ident
// disconnect ////////////////////////////////////////////////////////// // disconnect //////////////////////////////////////////////////////////
/// <summary>Disconnect all connections, including the local connection.</summary> /// <summary>Disconnect all connections, including the local connection.</summary>
public static void DisconnectAll()
{
DisconnectAllExternalConnections();
localConnection = null;
active = false;
}
/// <summary>Disconnect all currently connected clients except the local connection.</summary>
// synchronous: handles disconnect events and cleans up fully before returning! // synchronous: handles disconnect events and cleans up fully before returning!
public static void DisconnectAllExternalConnections() public static void DisconnectAll()
{ {
// disconnect and remove all connections. // disconnect and remove all connections.
// we can not use foreach here because if // we can not use foreach here because if
@ -540,18 +532,24 @@ public static void DisconnectAllExternalConnections()
// waiting for the Transport's callback. // waiting for the Transport's callback.
// -> it has checks to only run once. // -> it has checks to only run once.
// call OnDisconnected unless local player in host mode // call OnDisconnected unless local player in host mod
// TODO unnecessary check?
if (conn.connectionId != NetworkConnection.LocalConnectionId) if (conn.connectionId != NetworkConnection.LocalConnectionId)
OnTransportDisconnected(conn.connectionId); OnTransportDisconnected(conn.connectionId);
} }
// TODO this technically clears the local connection too. // cleanup
// which the function name would not suggest.
connections.Clear(); connections.Clear();
localConnection = null;
active = false;
} }
[Obsolete("DisconnectAllConnections was renamed to DisconnectAllExternalConnections because that's what it does.")] /// <summary>Disconnect all currently connected clients except the local connection.</summary>
public static void DisconnectAllConnections() => DisconnectAllExternalConnections(); [Obsolete("Call NetworkClient.DisconnectAll() instead")]
public static void DisconnectAllExternalConnections() => DisconnectAll();
[Obsolete("Call NetworkClient.DisconnectAll() instead")]
public static void DisconnectAllConnections() => DisconnectAll();
// add/remove/replace player /////////////////////////////////////////// // add/remove/replace player ///////////////////////////////////////////
/// <summary>Called by server after AddPlayer message to add the player for the connection.</summary> /// <summary>Called by server after AddPlayer message to add the player for the connection.</summary>

View File

@ -360,9 +360,8 @@ public void RemoveConnectionTest()
} }
[Test] [Test]
public void DisconnectAllConnectionsTest() public void DisconnectAllTest_RemoteConnection()
{ {
// listen // listen
NetworkServer.Listen(1); NetworkServer.Listen(1);
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0)); Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
@ -373,7 +372,7 @@ public void DisconnectAllConnectionsTest()
Assert.That(NetworkServer.connections.Count, Is.EqualTo(1)); Assert.That(NetworkServer.connections.Count, Is.EqualTo(1));
// disconnect all connections // disconnect all connections
NetworkServer.DisconnectAllExternalConnections(); NetworkServer.DisconnectAll();
// update transports. OnTransportDisconnected should be fired and // update transports. OnTransportDisconnected should be fired and
// clear all connections. // clear all connections.
@ -382,9 +381,8 @@ public void DisconnectAllConnectionsTest()
} }
[Test] [Test]
public void DisconnectAllTest() public void DisconnectAllTest_LocalConnection()
{ {
// listen // listen
NetworkServer.Listen(1); NetworkServer.Listen(1);
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0)); Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));