Skip to content

Commit

Permalink
fix: bug Client ConnectionState not set properly in Disconnect (#369)
Browse files Browse the repository at this point in the history
* bug: client connectionState not properly set on Disconnect

* fix: remove None state as its confusing and useless
  • Loading branch information
uweeby committed Oct 2, 2020
1 parent 46b2115 commit 74298c5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Assets/Mirror/Runtime/NetworkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ namespace Mirror

public enum ConnectState
{
None,
Disconnected,
Connecting,
Connected,
Disconnected
}

/// <summary>
Expand Down Expand Up @@ -64,7 +63,7 @@ public class NetworkClient : MonoBehaviour, INetworkClient
/// </summary>
public NetworkIdentity LocalPlayer => Connection?.Identity;

internal ConnectState connectState = ConnectState.None;
internal ConnectState connectState = ConnectState.Disconnected;

/// <summary>
/// active is true while a client is connecting/connected
Expand Down Expand Up @@ -337,7 +336,7 @@ void Cleanup()
isSpawnFinished = false;
hostServer = null;

connectState = ConnectState.None;
connectState = ConnectState.Disconnected;

if (authenticator != null)
{
Expand Down
8 changes: 8 additions & 0 deletions Assets/Tests/Runtime/ClientServerComponentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,13 @@ GameObject SpawnDelegateTest(Vector3 position, Guid assetId)
}
return null;
}

[UnityTest]
public IEnumerator ClientDisconnectTest() => RunAsync(async () =>
{
client.Disconnect();
await WaitFor(() => client.connectState == ConnectState.Disconnected);
});
}
}
8 changes: 8 additions & 0 deletions Assets/Tests/Runtime/NetworkClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,13 @@ public void GetNewConnectionTest()
{
Assert.That(client.GetNewConnection(Substitute.For<IConnection>()), Is.Not.Null);
}

[UnityTest]
public IEnumerator ClientDisconnectTest() => RunAsync(async () =>
{
client.Disconnect();
await WaitFor(() => client.connectState == ConnectState.Disconnected);
});
}
}

0 comments on commit 74298c5

Please sign in to comment.