Skip to content

Commit c69afe1

Browse files
committed
Fix tests
1 parent 7c90c5e commit c69afe1

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public void Serialize(FastBufferWriter writer, int targetVersion)
5656
}
5757
}
5858

59+
writer.WriteValueSafe(ChangeMessageType);
60+
5961
if (ChangeMessageType == ChangeType.OwnershipFlagsUpdate || ChangeMessageType == ChangeType.OwnershipChanging || ChangeMessageType == ChangeType.RequestApproved)
6062
{
6163
writer.WriteValueSafe(OwnershipFlags);
@@ -155,7 +157,7 @@ public void Handle(ref NetworkContext context)
155157
// If ownership is changing (either a straight change or a request approval), then run through the ownership changed sequence
156158
// Note: There is some extended ownership script at the bottom of HandleOwnershipChange
157159
// If not in distributed authority mode, ChangeMessageType will always be OwnershipChanging.
158-
if (ChangeMessageType == ChangeType.OwnershipChanging || ChangeMessageType == ChangeType.RequestApproved)
160+
if (ChangeMessageType == ChangeType.OwnershipChanging || ChangeMessageType == ChangeType.RequestApproved || !networkManager.DistributedAuthorityMode)
159161
{
160162
HandleOwnershipChange(ref context);
161163
}
@@ -312,7 +314,8 @@ private bool HandleDAHostMessageForwarding(ref NetworkManager networkManager, ul
312314
{
313315
message.OwnershipRequestResponseStatus = OwnershipRequestResponseStatus;
314316
networkManager.ConnectionManager.SendMessage(ref message, NetworkDelivery.Reliable, RequestClientId);
315-
// We don't want the local DAHost's client to process this message, so exit early
317+
318+
// We don't want the local DAHost's client to process this message
316319
return false;
317320
}
318321
}
@@ -322,31 +325,21 @@ private bool HandleDAHostMessageForwarding(ref NetworkManager networkManager, ul
322325
if (OwnerClientId != networkManager.LocalClientId)
323326
{
324327
networkManager.ConnectionManager.SendMessage(ref message, NetworkDelivery.Reliable, OwnerClientId);
325-
// We don't want the local DAHost's client to process this message, so exit early
328+
329+
// We don't want the local DAHost's client to process this message
326330
return false;
327331
}
328-
// Otherwise, fall through and process the request.
329332
}
330333
else
331334
{
332335
foreach (var clientId in clientList)
333336
{
334-
if (clientId == networkManager.LocalClientId)
337+
// Don't forward to self or originating client
338+
if (clientId == networkManager.LocalClientId || clientId == senderId)
335339
{
336340
continue;
337341
}
338342

339-
switch (ChangeMessageType)
340-
{
341-
// If ownership is changing and this is not an ownership request approval then ignore the SenderId
342-
case ChangeType.OwnershipChanging when senderId == clientId:
343-
// If it is just updating flags then ignore sending to the owner
344-
case ChangeType.OwnershipFlagsUpdate when clientId == OwnerClientId:
345-
// If it is a request approval, then ignore the RequestClientId
346-
case ChangeType.RequestApproved when clientId == RequestClientId:
347-
continue;
348-
}
349-
350343
networkManager.ConnectionManager.SendMessage(ref message, NetworkDelivery.Reliable, clientId);
351344
}
352345
}

com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,12 +575,12 @@ internal void ChangeOwnership(NetworkObject networkObject, ulong clientId, bool
575575
ChangeMessageType = isRequestApproval ? ChangeOwnershipMessage.ChangeType.RequestApproved : ChangeOwnershipMessage.ChangeType.OwnershipChanging,
576576
NetworkObjectId = networkObject.NetworkObjectId,
577577
OwnerClientId = networkObject.OwnerClientId,
578-
DistributedAuthorityMode = NetworkManager.DistributedAuthorityMode,
578+
DistributedAuthorityMode = true,
579579
RequestClientId = networkObject.PreviousOwnerId,
580580
OwnershipFlags = (ushort)networkObject.Ownership,
581581
};
582-
// If we are connected to the CMB service or not the DAHost (i.e. pure DA-Clients only)
583582

583+
// If we are connected to the CMB service or not the DAHost (i.e. pure DA-Clients only)
584584
if (NetworkManager.CMBServiceConnection || !NetworkManager.DAHost)
585585
{
586586
// Always update the network properties in distributed authority mode for the client gaining ownership

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ internal class OwnershipPermissionsTests : IntegrationTestWithApproximation
1717

1818
protected override int NumberOfClients => 4;
1919

20+
// TODO: [CmbServiceTests] Remove this once MTTB-1570 is resolved.
21+
protected override bool UseCMBService()
22+
{
23+
return false;
24+
}
25+
2026
public OwnershipPermissionsTests() : base(HostOrServer.DAHost)
2127
{
2228
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ internal static string GetCMBServiceEnvironentVariable()
197197
#if USE_CMB_SERVICE
198198
return "true";
199199
#else
200-
return Environment.GetEnvironmentVariable("USE_CMB_SERVICE") ?? "true";
200+
return Environment.GetEnvironmentVariable("USE_CMB_SERVICE") ?? "false";
201201
#endif
202202
}
203203

0 commit comments

Comments
 (0)