Skip to content

Commit a89bfbb

Browse files
update - 1:1 Review changes
Modifications after doing 1:1 with Emma.
1 parent 528d120 commit a89bfbb

File tree

8 files changed

+34
-74
lines changed

8 files changed

+34
-74
lines changed

com.unity.netcode.gameobjects/Runtime/Messaging/Messages/ConnectionApprovedMessage.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ public void Handle(ref NetworkContext context)
275275

276276
foreach (var clientId in ConnectedClientIds)
277277
{
278+
// DANGO-TODO: Revisit the entire connection sequence and determine why we would need to check both cases as we shouldn't have to =or= we could
279+
// try removing this after the Rust server connection sequence stuff is resolved. (Might be only needed if scene management is disabled)
278280
// If there is any disconnect between the connection sequence of Ids vs ConnectedClients, then add the client.
279281
if (!networkManager.ConnectionManager.ConnectedClientIds.Contains(clientId) || !networkManager.ConnectionManager.ConnectedClients.ContainsKey(clientId))
280282
{

com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTest.cs

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -194,18 +194,7 @@ protected NetworkManager GetAuthorityNetworkManager()
194194
return client;
195195
}
196196
}
197-
198-
// If we have not found a session owner and we are not
199-
// auto-starting the session owner, then return the first
200-
// client NetworkManager.
201-
if (!ShouldAutoStartSessionOwner())
202-
{
203-
return m_NetworkManagers[0];
204-
}
205-
else
206-
{
207-
Assert.Fail("No DA session owner found!");
208-
}
197+
Assert.Fail("No DA session owner found!");
209198
}
210199

211200
return m_ServerNetworkManager;
@@ -255,7 +244,7 @@ private bool GetServiceEnvironmentVariable()
255244
{
256245
if (!m_UseCmbServiceEnv && m_UseCmbServiceEnvString == null)
257246
{
258-
m_UseCmbServiceEnvString = Environment.GetEnvironmentVariable("USE_CMB_SERVICE") ?? "false";
247+
m_UseCmbServiceEnvString = NetcodeIntegrationTestHelpers.GetCMBServiceEnvironentVariable();
259248
if (bool.TryParse(m_UseCmbServiceEnvString.ToLower(), out bool isTrue))
260249
{
261250
m_UseCmbServiceEnv = isTrue;
@@ -276,11 +265,7 @@ private bool GetServiceEnvironmentVariable()
276265
/// <returns>true if a DAHost test should run against a hosted CMB service instance; otherwise false</returns>
277266
protected virtual bool UseCMBService()
278267
{
279-
#if USE_CMB_SERVICE
280-
return true;
281-
#else
282268
return m_UseCmbService;
283-
#endif
284269
}
285270

286271
protected virtual NetworkTopologyTypes OnGetNetworkTopologyType()
@@ -983,13 +968,8 @@ private void ClientNetworkManagerPostStart(NetworkManager networkManager)
983968
m_PlayerNetworkObjects.Add(networkManager.LocalClientId, new Dictionary<ulong, NetworkObject>());
984969
}
985970

986-
#if UNITY_2023_1_OR_NEWER
987971
// Get all player instances for the current client NetworkManager instance
988972
var clientPlayerClones = Object.FindObjectsByType<NetworkObject>(FindObjectsSortMode.None).Where((c) => c.IsPlayerObject && c.OwnerClientId == networkManager.LocalClientId).ToList();
989-
#else
990-
// Get all player instances for the current client NetworkManager instance
991-
var clientPlayerClones = Object.FindObjectsOfType<NetworkObject>().Where((c) => c.IsPlayerObject && c.OwnerClientId == networkManager.LocalClientId).ToList();
992-
#endif
993973
// Add this player instance to each client player entry
994974
foreach (var playerNetworkObject in clientPlayerClones)
995975
{
@@ -1004,13 +984,8 @@ private void ClientNetworkManagerPostStart(NetworkManager networkManager)
1004984
m_PlayerNetworkObjects[playerNetworkObject.NetworkManager.LocalClientId].Add(networkManager.LocalClientId, playerNetworkObject);
1005985
}
1006986
}
1007-
#if UNITY_2023_1_OR_NEWER
1008987
// For late joining clients, add the remaining (if any) cloned versions of each client's player
1009988
clientPlayerClones = Object.FindObjectsByType<NetworkObject>(FindObjectsSortMode.None).Where((c) => c.IsPlayerObject && c.NetworkManager == networkManager).ToList();
1010-
#else
1011-
// For late joining clients, add the remaining (if any) cloned versions of each client's player
1012-
clientPlayerClones = Object.FindObjectsOfType<NetworkObject>().Where((c) => c.IsPlayerObject && c.NetworkManager == networkManager).ToList();
1013-
#endif
1014989
foreach (var playerNetworkObject in clientPlayerClones)
1015990
{
1016991
if (!m_PlayerNetworkObjects[networkManager.LocalClientId].ContainsKey(playerNetworkObject.OwnerClientId))
@@ -1058,6 +1033,10 @@ protected virtual bool ShouldCheckForSpawnedPlayers()
10581033
/// <summary>
10591034
/// Starts the session owner and awaits for it to connect before starting the remaining clients.
10601035
/// </summary>
1036+
/// <remarks>
1037+
/// DANGO-TODO: Renove this when the Rust server connection sequence is fixed and we don't have to pre-start
1038+
/// the session owner.
1039+
/// </remarks>
10611040
private IEnumerator StartSessionOwner()
10621041
{
10631042
VerboseDebug("Starting session owner...");
@@ -1068,14 +1047,6 @@ private IEnumerator StartSessionOwner()
10681047
VerboseDebug("Session owner connected and approved.");
10691048
}
10701049

1071-
/// <summary>
1072-
/// Determines whether the session owner will be auto-started prior to any other client
1073-
/// </summary>
1074-
internal virtual bool ShouldAutoStartSessionOwner()
1075-
{
1076-
return true;
1077-
}
1078-
10791050
/// <summary>
10801051
/// This starts the server and clients as long as <see cref="CanStartServerAndClients"/>
10811052
/// returns true.
@@ -1086,7 +1057,9 @@ protected IEnumerator StartServerAndClients()
10861057
{
10871058
VerboseDebug($"Entering {nameof(StartServerAndClients)}");
10881059

1089-
if (m_UseCmbService && ShouldAutoStartSessionOwner())
1060+
// DANGO-TODO: Renove this when the Rust server connection sequence is fixed and we don't have to pre-start
1061+
// the session owner.
1062+
if (m_UseCmbService)
10901063
{
10911064
VerboseDebug("Using a distributed authority CMB Server for connection.");
10921065
yield return StartSessionOwner();
@@ -2018,23 +1991,8 @@ public NetcodeIntegrationTest(HostOrServer hostOrServer)
20181991
InitializeTestConfiguration(m_NetworkTopologyType, hostOrServer);
20191992
}
20201993

2021-
/// <summary>
2022-
/// Override this virtual method to execute script that runs before the base class constructor has finished executing.<br />
2023-
/// </summary>
2024-
/// <remarks>
2025-
/// ***NOTE***
2026-
/// When this method is invoked there will have been no properties set (i.e. nothing is configured). <br />
2027-
/// Primarily this is to set things like environemnt variables or other more external configurations that could
2028-
/// determine how the <see cref="NetcodeIntegrationTest"/> is configured.
2029-
/// </remarks>
2030-
protected virtual void OnPreInitializeConfiguration()
2031-
{
2032-
}
2033-
20341994
private void InitializeTestConfiguration(NetworkTopologyTypes networkTopologyType, HostOrServer? hostOrServer)
20351995
{
2036-
OnPreInitializeConfiguration();
2037-
20381996
NetworkMessageManager.EnableMessageOrderConsoleLog = false;
20391997

20401998
// Set m_NetworkTopologyType first because m_DistributedAuthority is calculated from it.

com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,26 @@ public static void RegisterHandlers(NetworkManager networkManager, bool serverSi
172172
}
173173
}
174174

175+
/// <summary>
176+
/// Gets the CMB_SERVICE environemnt variable or returns "false" if it does not exist
177+
/// </summary>
178+
/// <returns>string</returns>
179+
internal static string GetCMBServiceEnvironentVariable()
180+
{
181+
#if USE_CMB_SERVICE
182+
return "true";
183+
#else
184+
return Environment.GetEnvironmentVariable("USE_CMB_SERVICE") ?? "false";
185+
#endif
186+
}
187+
175188
/// <summary>
176189
/// Use for non <see cref="NetcodeIntegrationTest"/> derived integration tests to automatically ignore the
177190
/// test if running against a CMB server.
178191
/// </summary>
179192
internal static void IgnoreIfServiceEnviromentVariableSet()
180193
{
181-
if (bool.TryParse(Environment.GetEnvironmentVariable("USE_CMB_SERVICE") ?? "false", out bool isTrue) ? isTrue : false)
194+
if (bool.TryParse(GetCMBServiceEnvironentVariable(), out bool isTrue) ? isTrue : false)
182195
{
183196
Assert.Ignore("[CMB-Server Test Run] Skipping non-distributed authority test.");
184197
}
@@ -327,7 +340,7 @@ internal static NetworkManager CreateNewClient(int identifier, bool mockTranspor
327340
public static bool CreateNewClients(int clientCount, out NetworkManager[] clients, bool useMockTransport = false, bool useCmbService = false)
328341
{
329342
clients = new NetworkManager[clientCount];
330-
// Pre-identify NetworkManager identifiers based on network topology type
343+
// Pre-identify NetworkManager identifiers based on network topology type (Rust server starts at client identifier 1 and considers itself 0)
331344
var startCount = useCmbService ? 1 : 0;
332345
for (int i = 0; i < clientCount; i++)
333346
{
@@ -549,6 +562,8 @@ public static bool Start(bool host, NetworkManager server, NetworkManager[] clie
549562

550563
foreach (var client in clients)
551564
{
565+
// DANGO-TODO: Renove this entire check when the Rust server connection sequence is fixed and we don't have to pre-start
566+
// the session owner.
552567
if (client.IsConnectedClient)
553568
{
554569
// Skip starting the session owner

com.unity.netcode.gameobjects/Tests/Runtime/DistributedAuthority/DistributedAuthorityCodecTests.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace Unity.Netcode.RuntimeTests
3030
/// </remarks>
3131
internal class DistributedAuthorityCodecTests : NetcodeIntegrationTest
3232
{
33-
protected override int NumberOfClients => 1;
33+
protected override int NumberOfClients => 0;
3434

3535
// Use the CMB Service for all tests
3636
protected override bool UseCMBService() => true;
@@ -68,14 +68,6 @@ public void TestAuthorityRpc(byte[] _)
6868
}
6969
}
7070

71-
/// <summary>
72-
/// Don't auto start the session owner for codec tests
73-
/// </summary>
74-
internal override bool ShouldAutoStartSessionOwner()
75-
{
76-
return false;
77-
}
78-
7971
protected override void OnOneTimeSetup()
8072
{
8173
// Prevents the tests from running if no CMB Service is detected

com.unity.netcode.gameobjects/Tests/Runtime/NetworkBehaviourUpdaterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public NetworkBehaviourUpdaterTests(HostOrServer hostOrServer, int numberOfClien
168168
SecondType = second
169169
};
170170
// Adjust the client count if connecting to the service.
171-
m_ClientCount = UseCMBService() ? numberOfClients + 1 : numberOfClients;
171+
m_ClientCount = numberOfClients;
172172
}
173173

174174
protected override IEnumerator OnSetup()

com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectSpawnManyObjectsTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public IEnumerator WhenManyObjectsAreSpawnedAtOnce_AllAreReceived()
6868

6969
AssertOnTimeout($"Timed out waiting for the client to spawn {k_SpawnedObjects} objects! Time to spawn: {timeSpawned} | Time to timeout: {timeStarted - Time.realtimeSinceStartup}", timeoutHelper);
7070

71+
// Provide one full tick for all messages to finish being processed.
72+
// DANGO-TODO: Determine if this is only when testing against Rust server (i.e. messages still pending and clients shutting down before they are dequeued)
7173
yield return s_DefaultWaitForTick;
7274
}
7375
}

com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariable/NetworkVarBufferCopyTest.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,10 @@ public override void OnNetworkSpawn()
101101
base.OnNetworkSpawn();
102102
}
103103
}
104-
protected override int NumberOfClients => m_ClientCount;
105-
106-
private const int k_ClientCount = 1;
107-
private int m_ClientCount = k_ClientCount;
104+
protected override int NumberOfClients => 1;
108105

109106
public NetworkVarBufferCopyTest(HostOrServer hostOrServer) : base(hostOrServer)
110107
{
111-
// Adjust the client count if connecting to the CMB service.
112-
m_ClientCount = UseCMBService() ? k_ClientCount + 1 : k_ClientCount;
113108
}
114109

115110
private static List<DummyNetBehaviour> s_ClientDummyNetBehavioursSpawned = new List<DummyNetBehaviour>();

com.unity.netcode.gameobjects/Tests/Runtime/Physics/NetworkRigidbodyTest.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,8 @@ protected void Log(string msg)
339339
[TestFixture(HostOrServer.DAHost, ContactEventTypes.WithInfo)]
340340
internal class RigidbodyContactEventManagerTests : IntegrationTestWithApproximation
341341
{
342-
protected override int NumberOfClients => m_ClientCount;
342+
protected override int NumberOfClients => 1;
343343

344-
private const int k_ClientCount = 1;
345-
private int m_ClientCount = k_ClientCount;
346344
private GameObject m_RigidbodyContactEventManager;
347345

348346
public enum ContactEventTypes
@@ -356,8 +354,6 @@ public enum ContactEventTypes
356354

357355
public RigidbodyContactEventManagerTests(HostOrServer hostOrServer, ContactEventTypes contactEventType) : base(hostOrServer)
358356
{
359-
// Adjust the client count if connecting to the CMB service.
360-
m_ClientCount = UseCMBService() ? k_ClientCount + 1 : k_ClientCount;
361357
m_ContactEventType = contactEventType;
362358
}
363359

0 commit comments

Comments
 (0)