Skip to content

Commit 3289148

Browse files
committed
Merge branch 'feat/yamato-rust-tests' into fix/mtt-11522-websockets-dont-exist-on-server-build
2 parents 167bc31 + 5cd7efd commit 3289148

File tree

6 files changed

+172
-80
lines changed

6 files changed

+172
-80
lines changed

.yamato/desktop-standalone-tests.yml

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Builds are made on each supported editor as in project.metafile declaration
88
# Builds are made with different scripting backends as in project.metafile declaration
99
# ARM64 architectures are for now not considered since Windows_arm64 is recommended to use only after builds (would require separation here) and when it comes to macOS_arm64 there is problem with OpenCL not being available
10-
10+
1111
# Build phase
1212
{% for project in projects.default -%}
1313
{% for platform in test_platforms.desktop -%}
@@ -24,20 +24,21 @@ desktop_standalone_build_{{ project.name }}_{{ platform.name }}_{{ backend }}_{{
2424
{% if platform.name == "ubuntu" %}
2525
- sudo apt-get update -q
2626
- sudo apt install -qy imagemagick
27+
2728
{% endif %}
2829
- pip install unity-downloader-cli --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple
29-
30+
3031
# Platform specific UTR setup
3132
- |
3233
{% if platform.name == "win" %}
3334
curl -s https://artifactory.prd.it.unity3d.com/artifactory/unity-tools-local/utr-standalone/utr.bat --output utr.bat
3435
{% else %}
3536
curl -s https://artifactory.prd.it.unity3d.com/artifactory/unity-tools-local/utr-standalone/utr --output utr && chmod +x utr
3637
{% endif %}
37-
38+
3839
# Installing editor
3940
- unity-downloader-cli -u {{ editor }} -c Editor {% if backend == "il2cpp" %} -c il2cpp {% endif %} --fast --wait
40-
41+
4142
# Build Player
4243
- |
4344
{% if platform.name == "win" %}
@@ -53,17 +54,17 @@ desktop_standalone_build_{{ project.name }}_{{ platform.name }}_{{ backend }}_{{
5354
logs:
5455
paths:
5556
- "artifacts/**/*"
56-
57+
5758
dependencies:
5859
- .yamato/project-pack.yml#project_pack_-_{{ project.name }}_{{ platform.name }}
5960
{% endfor -%}
6061
{% endfor -%}
6162
{% endfor -%}
6263
{% endfor -%}
63-
64-
65-
66-
64+
65+
66+
67+
6768
# Run phase
6869
{% for project in projects.default -%}
6970
{% for platform in test_platforms.desktop -%}
@@ -75,6 +76,8 @@ desktop_standalone_test_{{ project.name }}_{{ platform.name }}_{{ backend }}_{{
7576
type: {% if platform.name == "mac" %} {{ platform.type }} {% else %} {{ platform.type }}::GPU {% endif %}
7677
image: {{ platform.image }}
7778
flavor: {{ platform.flavor }}
79+
variables:
80+
ECHO_SERVER_PORT: "7788"
7881
commands:
7982
# Platform specific UTR setup
8083
- |
@@ -86,7 +89,19 @@ desktop_standalone_test_{{ project.name }}_{{ platform.name }}_{{ backend }}_{{
8689
- pip install unity-downloader-cli --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple
8790

8891
- unity-downloader-cli -u {{ editor }} -c Editor {% if backend == "il2cpp" %} -c il2cpp {% endif %} --fast --wait
89-
92+
93+
# If ubuntu, run rust echo server
94+
{% if platform.name == "ubuntu" %}
95+
- |
96+
git clone https://github.com/Unity-Technologies/mps-common-multiplayer-backend.git
97+
# Install rust
98+
- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
99+
# Build the echo server
100+
- cd ./mps-common-multiplayer-backend/runtime && $HOME/.cargo/bin/cargo build --example ngo_echo_server
101+
# Run the echo server in the background - this will reuse the artifacts from the build
102+
- cd ./mps-common-multiplayer-backend/runtime && $HOME/.cargo/bin/cargo run --example ngo_echo_server -- --port $ECHO_SERVER_PORT &
103+
{% endif %}
104+
90105
# Run Standalone tests
91106
- |
92107
{% if platform.name == "win" %}

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
1515

1616
### Fixed
1717

18+
- Fixed `ChangeOwnership` changing ownership to clients that are not observers. This also happened with automated object distribution. (#3323)
1819
- Fixed issue where `AnticipatedNetworkVariable` previous value returned by `AnticipatedNetworkVariable.OnAuthoritativeValueChanged` is updated correctly on the non-authoritative side. (#3306)
1920
- Fixed `OnClientConnectedCallback` passing incorrect `clientId` when scene management is disabled. (#3312)
2021
- Fixed issue where the `NetworkObject.Ownership` custom editor did not take the default "Everything" flag into consideration. (#3305)

com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs

Lines changed: 73 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,18 +1122,16 @@ internal void OnClientDisconnectFromServer(ulong clientId)
11221122
{
11231123
if (!playerObject.DontDestroyWithOwner)
11241124
{
1125-
// DANGO-TODO: This is something that would be best for CMB Service to handle as it is part of the disconnection process
11261125
// If a player NetworkObject is being despawned, make sure to remove all children if they are marked to not be destroyed
11271126
// with the owner.
1128-
if (NetworkManager.DistributedAuthorityMode && NetworkManager.DAHost)
1127+
if (NetworkManager.DAHost)
11291128
{
11301129
// Remove any children from the player object if they are not going to be destroyed with the owner
11311130
var childNetworkObjects = playerObject.GetComponentsInChildren<NetworkObject>();
11321131
foreach (var child in childNetworkObjects)
11331132
{
1134-
// TODO: We have always just removed all children, but we might think about changing this to preserve the nested child
1135-
// hierarchy.
1136-
if (child.DontDestroyWithOwner && child.transform.transform.parent != null)
1133+
// TODO: We have always just removed all children, but we might think about changing this to preserve the nested child hierarchy.
1134+
if (child.DontDestroyWithOwner && child.transform.transform.parent)
11371135
{
11381136
// If we are here, then we are running in DAHost mode and have the authority to remove the child from its parent
11391137
child.AuthorityAppliedParenting = true;
@@ -1158,10 +1156,7 @@ internal void OnClientDisconnectFromServer(ulong clientId)
11581156
}
11591157
else if (!NetworkManager.ShutdownInProgress)
11601158
{
1161-
if (!NetworkManager.ShutdownInProgress)
1162-
{
1163-
playerObject.RemoveOwnership();
1164-
}
1159+
playerObject.RemoveOwnership();
11651160
}
11661161
}
11671162

@@ -1175,7 +1170,7 @@ internal void OnClientDisconnectFromServer(ulong clientId)
11751170
for (int i = clientOwnedObjects.Count - 1; i >= 0; i--)
11761171
{
11771172
var ownedObject = clientOwnedObjects[i];
1178-
if (ownedObject != null)
1173+
if (ownedObject)
11791174
{
11801175
// If destroying with owner, then always despawn and destroy (or defer destroying to prefab handler)
11811176
if (!ownedObject.DontDestroyWithOwner)
@@ -1196,68 +1191,93 @@ internal void OnClientDisconnectFromServer(ulong clientId)
11961191
}
11971192
else if (!NetworkManager.ShutdownInProgress)
11981193
{
1194+
// DANGO-TODO: We will want to match how the CMB service handles this. For now, we just try to evenly distribute
1195+
// ownership.
11991196
// NOTE: All of the below code only handles ownership transfer.
12001197
// For client-server, we just remove the ownership.
12011198
// For distributed authority, we need to change ownership based on parenting
12021199
if (NetworkManager.DistributedAuthorityMode)
12031200
{
1204-
// Only NetworkObjects that have the OwnershipStatus.Distributable flag set and no parent
1205-
// (ownership is transferred to all children) will have their ownership redistributed.
1206-
if (ownedObject.IsOwnershipDistributable && ownedObject.GetCachedParent() == null && !ownedObject.IsOwnershipSessionOwner)
1201+
// Only NetworkObjects that have the OwnershipStatus.Distributable flag set and are not OwnershipSessionOwner are distributed.
1202+
// If the object has a parent - skip it for now, it will be distributed when its root parent is distributed.
1203+
if (!ownedObject.IsOwnershipDistributable || ownedObject.IsOwnershipSessionOwner || ownedObject.GetCachedParent())
1204+
{
1205+
continue;
1206+
}
1207+
1208+
if (ownedObject.IsOwnershipLocked)
1209+
{
1210+
ownedObject.SetOwnershipLock(false);
1211+
}
1212+
1213+
var targetOwner = NetworkManager.ServerClientId;
1214+
// Cycle through the full count of clients to find
1215+
// the next viable owner. If none are found, then
1216+
// the DAHost defaults to the owner.
1217+
for (int j = 0; j < remainingClients.Count; j++)
12071218
{
1208-
if (ownedObject.IsOwnershipLocked)
1219+
clientCounter++;
1220+
clientCounter = clientCounter % predictedClientCount;
1221+
if (ownedObject.Observers.Contains(remainingClients[clientCounter].ClientId))
12091222
{
1210-
ownedObject.SetOwnershipLock(false);
1223+
targetOwner = remainingClients[clientCounter].ClientId;
1224+
break;
12111225
}
1226+
}
1227+
if (EnableDistributeLogging)
1228+
{
1229+
Debug.Log($"[Disconnected][Client-{clientId}][NetworkObjectId-{ownedObject.NetworkObjectId} Distributed to Client-{targetOwner}");
1230+
}
12121231

1213-
// DANGO-TODO: We will want to match how the CMB service handles this. For now, we just try to evenly distribute
1214-
// ownership.
1215-
var targetOwner = NetworkManager.ServerClientId;
1216-
if (predictedClientCount > 1)
1232+
NetworkManager.SpawnManager.ChangeOwnership(ownedObject, targetOwner, true);
1233+
1234+
// Ownership gets passed down to all children that have the same owner.
1235+
var childNetworkObjects = ownedObject.GetComponentsInChildren<NetworkObject>();
1236+
foreach (var childObject in childNetworkObjects)
1237+
{
1238+
// We already changed ownership for this
1239+
if (childObject == ownedObject)
12171240
{
1218-
clientCounter++;
1219-
clientCounter = clientCounter % predictedClientCount;
1220-
targetOwner = remainingClients[clientCounter].ClientId;
1241+
continue;
12211242
}
1222-
if (EnableDistributeLogging)
1243+
// If the client owner disconnected, it is ok to unlock this at this point in time.
1244+
if (childObject.IsOwnershipLocked)
12231245
{
1224-
Debug.Log($"[Disconnected][Client-{clientId}][NetworkObjectId-{ownedObject.NetworkObjectId} Distributed to Client-{targetOwner}");
1246+
childObject.SetOwnershipLock(false);
12251247
}
1226-
NetworkManager.SpawnManager.ChangeOwnership(ownedObject, targetOwner, true);
1227-
// DANGO-TODO: Should we try handling inactive NetworkObjects?
1228-
// Ownership gets passed down to all children that have the same owner.
1229-
var childNetworkObjects = ownedObject.GetComponentsInChildren<NetworkObject>();
1230-
foreach (var childObject in childNetworkObjects)
1248+
1249+
// Ignore session owner marked objects
1250+
if (childObject.IsOwnershipSessionOwner)
12311251
{
1232-
// We already changed ownership for this
1233-
if (childObject == ownedObject)
1234-
{
1235-
continue;
1236-
}
1237-
// If the client owner disconnected, it is ok to unlock this at this point in time.
1238-
if (childObject.IsOwnershipLocked)
1239-
{
1240-
childObject.SetOwnershipLock(false);
1241-
}
1252+
continue;
1253+
}
12421254

1243-
// Ignore session owner marked objects
1244-
if (childObject.IsOwnershipSessionOwner)
1245-
{
1246-
continue;
1247-
}
1255+
// If the child's owner is not the client disconnected and the objects are marked with either distributable or transferable, then
1256+
// do not change ownership.
1257+
if (childObject.OwnerClientId != clientId && (childObject.IsOwnershipDistributable || childObject.IsOwnershipTransferable))
1258+
{
1259+
continue;
1260+
}
12481261

1249-
// If the child's owner is not the client disconnected and the objects are marked with either distributable or transferable, then
1250-
// do not change ownership.
1251-
if (childObject.OwnerClientId != clientId && (childObject.IsOwnershipDistributable || childObject.IsOwnershipTransferable))
1262+
var childOwner = targetOwner;
1263+
if (!childObject.Observers.Contains(childOwner))
1264+
{
1265+
for (int j = 0; j < remainingClients.Count; j++)
12521266
{
1253-
continue;
1267+
clientCounter++;
1268+
clientCounter = clientCounter % predictedClientCount;
1269+
if (ownedObject.Observers.Contains(remainingClients[clientCounter].ClientId))
1270+
{
1271+
childOwner = remainingClients[clientCounter].ClientId;
1272+
break;
1273+
}
12541274
}
1275+
}
12551276

1256-
NetworkManager.SpawnManager.ChangeOwnership(childObject, targetOwner, true);
1257-
if (EnableDistributeLogging)
1258-
{
1259-
Debug.Log($"[Disconnected][Client-{clientId}][Child of {ownedObject.NetworkObjectId}][NetworkObjectId-{ownedObject.NetworkObjectId} Distributed to Client-{targetOwner}");
1260-
}
1277+
NetworkManager.SpawnManager.ChangeOwnership(childObject, childOwner, true);
1278+
if (EnableDistributeLogging)
1279+
{
1280+
Debug.Log($"[Disconnected][Client-{clientId}][Child of {ownedObject.NetworkObjectId}][NetworkObjectId-{ownedObject.NetworkObjectId} Distributed to Client-{targetOwner}");
12611281
}
12621282
}
12631283
}

0 commit comments

Comments
 (0)