-
Notifications
You must be signed in to change notification settings - Fork 450
fix: OnClientDisconnected client identifier is incorrect when pending client connection is denied [MTT-6376] #2569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
NoelStephensUnity
merged 10 commits into
develop
from
fix/client-disconnect-callback-after-denied
May 24, 2023
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
806fd70
fix
NoelStephensUnity 82786fe
test
NoelStephensUnity 8cb64c9
Update CHANGELOG.md
NoelStephensUnity 7552a6d
style
NoelStephensUnity 861e86a
style
NoelStephensUnity d1634b5
update
NoelStephensUnity 27ee4a6
test
NoelStephensUnity 07bdc93
style
NoelStephensUnity aa22588
style
NoelStephensUnity ccea359
Merge develop into fix/client-disconnect-callback-after-denied
netcode-ci-service File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
com.unity.netcode.gameobjects/Tests/Runtime/ClientApprovalDenied.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using NUnit.Framework; | ||
using Unity.Netcode.TestHelpers.Runtime; | ||
using UnityEngine.TestTools; | ||
|
||
|
||
namespace Unity.Netcode.RuntimeTests | ||
{ | ||
public class ClientApprovalDenied : NetcodeIntegrationTest | ||
{ | ||
protected override int NumberOfClients => 2; | ||
private bool m_ApproveConnection = true; | ||
private ulong m_PendingClientId = 0; | ||
private ulong m_DisconnectedClientId = 0; | ||
|
||
private List<ulong> m_DisconnectedClientIdentifiers = new List<ulong>(); | ||
|
||
private void ConnectionApproval(NetworkManager.ConnectionApprovalRequest connectionApprovalRequest, NetworkManager.ConnectionApprovalResponse connectionApprovalResponse) | ||
{ | ||
connectionApprovalResponse.Approved = m_ApproveConnection; | ||
connectionApprovalResponse.CreatePlayerObject = true; | ||
// When denied, store the client identifier to use for validating the client disconnected notification identifier matches | ||
if (!m_ApproveConnection) | ||
{ | ||
m_PendingClientId = connectionApprovalRequest.ClientNetworkId; | ||
} | ||
} | ||
|
||
protected override void OnNewClientCreated(NetworkManager networkManager) | ||
{ | ||
networkManager.NetworkConfig.ConnectionApproval = true; | ||
base.OnNewClientCreated(networkManager); | ||
} | ||
|
||
protected override bool ShouldWaitForNewClientToConnect(NetworkManager networkManager) | ||
{ | ||
return false; | ||
} | ||
|
||
/// <summary> | ||
/// Validates that when a pending client is denied approval the server-host | ||
/// OnClientDisconnected method will return the valid pending client identifier. | ||
/// </summary> | ||
[UnityTest] | ||
public IEnumerator ClientDeniedAndDisconnectionNotificationTest() | ||
{ | ||
m_ServerNetworkManager.NetworkConfig.ConnectionApproval = true; | ||
m_ServerNetworkManager.ConnectionApprovalCallback = ConnectionApproval; | ||
m_ApproveConnection = false; | ||
m_ServerNetworkManager.OnClientDisconnectCallback += OnClientDisconnectCallback; | ||
yield return CreateAndStartNewClient(); | ||
yield return WaitForConditionOrTimeOut(() => m_PendingClientId == m_DisconnectedClientId); | ||
AssertOnTimeout($"Timed out waiting for disconnect notification for pending Client-{m_PendingClientId}!"); | ||
|
||
// Validate that we don't get multiple disconnect notifications for clients being disconnected | ||
// Have a client disconnect remotely | ||
m_ClientNetworkManagers[0].Shutdown(); | ||
|
||
// Have the server disconnect a client | ||
m_ServerNetworkManager.DisconnectClient(m_ClientNetworkManagers[1].LocalClientId); | ||
m_ServerNetworkManager.OnClientDisconnectCallback -= OnClientDisconnectCallback; | ||
} | ||
|
||
private void OnClientDisconnectCallback(ulong clientId) | ||
{ | ||
Assert.False(m_DisconnectedClientIdentifiers.Contains(clientId), $"Received two disconnect notifications from Client-{clientId}!"); | ||
m_DisconnectedClientIdentifiers.Add(clientId); | ||
m_DisconnectedClientId = clientId; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
com.unity.netcode.gameobjects/Tests/Runtime/ClientApprovalDenied.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.