Skip to content

Commit c6a20c3

Browse files
feat: bumping to pre.10 (#678)
* bumping to pre.10 Fixing connection approval with new API updating comments to better reflect current state * adding changelog * Fix for new API breaking change * Removing useless ForceNetworkSerializeByMemcpy for FixedString32Bytes Update changelog * updating utilities package version as well * changing syntax in Utilities package to be supported by C#8.0 * removing old UTP adapter reference from assembly definition * Adding tools as a dependency in Utilities package * reverting bump to 2021 in utilities package supported unity version * Creating new asmdef for scripts using RNSM requiring Unity 2021 * adding eof character * updated changelog * updating changelogs for release Co-authored-by: LPLafontaineB <[email protected]>
1 parent 309ee34 commit c6a20c3

File tree

13 files changed

+95
-66
lines changed

13 files changed

+95
-66
lines changed

Assets/Scripts/Gameplay/ConnectionManagement/ServerGameNetPortal.cs

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -161,26 +161,27 @@ public bool AreAllClientsInServerScene()
161161
}
162162

163163
/// <summary>
164-
/// This logic plugs into the "ConnectionApprovalCallback" exposed by Netcode.NetworkManager, and is run every time a client connects to us.
165-
/// See ClientGameNetPortal.StartClient for the complementary logic that runs when the client starts its connection.
164+
/// This logic plugs into the "ConnectionApprovalResponse" exposed by Netcode.NetworkManager. It is run every time a client connects to us.
165+
/// The complementary logic that runs when the client starts its connection can be found in ClientGameNetPortal.StartClient.
166166
/// </summary>
167167
/// <remarks>
168-
/// Since our game doesn't have to interact with some third party authentication service to validate the identity of the new connection, our ApprovalCheck
169-
/// method is simple, and runs synchronously, invoking "callback" to signal approval at the end of the method. Netcode currently doesn't support the ability
170-
/// to send back more than a "true/false", which means we have to work a little harder to provide a useful error return to the client. To do that, we invoke a
171-
/// custom message in the same channel that Netcode uses for its connection callback. Since the delivery is NetworkDelivery.ReliableSequenced, we can be
172-
/// confident that our login result message will execute before any disconnect message.
168+
/// Multiple things can be done here, some asynchronously. For example, it could authenticate your user against an auth service like UGS' auth service. It can
169+
/// also send custom messages to connecting users before they receive their connection result (this is useful to set status messages client side
170+
/// when connection is refused, for example).
173171
/// </remarks>
174-
/// <param name="connectionData">binary data passed into StartClient. In our case this is the client's GUID, which is a unique identifier for their install of the game that persists across app restarts. </param>
175-
/// <param name="clientId">This is the clientId that Netcode assigned us on login. It does not persist across multiple logins from the same client. </param>
176-
/// <param name="connectionApprovedCallback">The delegate we must invoke to signal that the connection was approved or not. </param>
177-
void ApprovalCheck(byte[] connectionData, ulong clientId, NetworkManager.ConnectionApprovedDelegate connectionApprovedCallback)
172+
///
173+
/// <param name="request"> The initial request contains, among other things, binary data passed into StartClient. In our case, this is the client's GUID,
174+
/// which is a unique identifier for their install of the game that persists across app restarts.
175+
/// <param name="response"> Our response to the approval process. In case of connection refusal with custom return message, we delay using the Pending field.
176+
void ApprovalCheck(NetworkManager.ConnectionApprovalRequest request, NetworkManager.ConnectionApprovalResponse response)
178177
{
178+
var connectionData = request.Payload;
179+
var clientId = request.ClientNetworkId;
179180
if (connectionData.Length > k_MaxConnectPayload)
180181
{
181182
// If connectionData too high, deny immediately to avoid wasting time on the server. This is intended as
182183
// a bit of light protection against DOS attacks that rely on sending silly big buffers of garbage.
183-
connectionApprovedCallback(false, 0, false, null, null);
184+
response.Approved = false;
184185
return;
185186
}
186187

@@ -190,13 +191,14 @@ void ApprovalCheck(byte[] connectionData, ulong clientId, NetworkManager.Connect
190191
SessionManager<SessionPlayerData>.Instance.SetupConnectingPlayerSessionData(clientId, m_Portal.GetPlayerId(),
191192
new SessionPlayerData(clientId, m_Portal.PlayerName, m_Portal.AvatarRegistry.GetRandomAvatar().Guid.ToNetworkGuid(), 0, true));
192193

193-
connectionApprovedCallback(true, null, true, null, null);
194+
response.Approved = true;
195+
response.CreatePlayerObject = true;
194196
return;
195197
}
196198

197199
var payload = System.Text.Encoding.UTF8.GetString(connectionData);
198200
var connectionPayload = JsonUtility.FromJson<ConnectionPayload>(payload); // https://docs.unity3d.com/2020.2/Documentation/Manual/JSONSerialization.html
199-
var gameReturnStatus = GetConnectStatus(connectionPayload);
201+
var gameReturnStatus = CanClientConnect(connectionPayload);
200202

201203
if (gameReturnStatus == ConnectStatus.Success)
202204
{
@@ -207,28 +209,36 @@ void ApprovalCheck(byte[] connectionData, ulong clientId, NetworkManager.Connect
207209
//Populate our client scene map
208210
m_ClientSceneMap[clientId] = connectionPayload.clientScene;
209211

210-
// connection approval will create a player object for you
211-
connectionApprovedCallback(true, null, true, Vector3.zero, Quaternion.identity);
212-
213212
m_ConnectionEventPublisher.Publish(new ConnectionEventMessage() { ConnectStatus = ConnectStatus.Success, PlayerName = SessionManager<SessionPlayerData>.Instance.GetPlayerData(clientId)?.PlayerName });
213+
response.Approved = true;
214+
response.CreatePlayerObject = true;
215+
response.Position = Vector3.zero;
216+
response.Rotation = Quaternion.identity;
217+
return;
214218
}
215-
else
219+
220+
// In order for clients to not just get disconnected with no feedback, the server needs to tell the client why it disconnected it.
221+
// This could happen after an auth check on a service or because of gameplay reasons (server full, wrong build version, etc)
222+
// Since network objects haven't synced yet (still in the approval process), we need to send a custom message to clients, wait for
223+
// UTP to update a frame and flush that message, then give our response to NetworkManager's connection approval process, with a denied approval.
224+
IEnumerator WaitToDenyApproval(NetworkManager.ConnectionApprovalResponse response)
216225
{
217-
//TODO-FIXME:Netcode Issue #796. We should be able to send a reason and disconnect without a coroutine delay.
218-
//TODO:Netcode: In the future we expect Netcode to allow us to return more information as part of the
219-
//approval callback, so that we can provide more context on a reject. In the meantime we must provide
220-
//the extra information ourselves, and then wait a short time before manually close down the connection.
226+
response.Pending = true; // give some time for server to send connection status message to clients
227+
response.Approved = false;
221228
SendServerToClientConnectResult(clientId, gameReturnStatus);
222229
SendServerToClientSetDisconnectReason(clientId, gameReturnStatus);
223-
StartCoroutine(WaitToDenyApproval(connectionApprovedCallback));
224-
if (m_LobbyServiceFacade.CurrentUnityLobby != null)
225-
{
226-
m_LobbyServiceFacade.RemovePlayerFromLobbyAsync(connectionPayload.playerId, m_LobbyServiceFacade.CurrentUnityLobby.Id);
227-
}
230+
yield return null; // wait a frame so UTP can flush it's messages on next update
231+
response.Pending = false; // connection approval process can be finished.
232+
}
233+
234+
StartCoroutine(WaitToDenyApproval(response));
235+
if (m_LobbyServiceFacade.CurrentUnityLobby != null)
236+
{
237+
m_LobbyServiceFacade.RemovePlayerFromLobbyAsync(connectionPayload.playerId, m_LobbyServiceFacade.CurrentUnityLobby.Id);
228238
}
229239
}
230240

231-
ConnectStatus GetConnectStatus(ConnectionPayload connectionPayload)
241+
ConnectStatus CanClientConnect(ConnectionPayload connectionPayload)
232242
{
233243
if (m_Portal.NetManager.ConnectedClientsIds.Count >= CharSelectData.k_MaxLobbyPlayers)
234244
{
@@ -240,14 +250,7 @@ ConnectStatus GetConnectStatus(ConnectionPayload connectionPayload)
240250
return ConnectStatus.IncompatibleBuildType;
241251
}
242252

243-
return SessionManager<SessionPlayerData>.Instance.IsDuplicateConnection(connectionPayload.playerId) ?
244-
ConnectStatus.LoggedInAgain : ConnectStatus.Success;
245-
}
246-
247-
static IEnumerator WaitToDenyApproval(NetworkManager.ConnectionApprovedDelegate connectionApprovedCallback)
248-
{
249-
yield return new WaitForSeconds(0.5f);
250-
connectionApprovedCallback(false, 0, false, null, null);
253+
return SessionManager<SessionPlayerData>.Instance.IsDuplicateConnection(connectionPayload.playerId) ? ConnectStatus.LoggedInAgain : ConnectStatus.Success;
251254
}
252255

253256
IEnumerator WaitToShutdown()

Assets/Scripts/Gameplay/GameplayObjects/NetworkNameState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class NetworkNameState : NetworkBehaviour
1919
/// </summary>
2020
public struct FixedPlayerName : INetworkSerializable
2121
{
22-
ForceNetworkSerializeByMemcpy<FixedString32Bytes> m_Name; // using ForceNetworkSerializeByMemcpy to force compatibility between FixedString and NetworkSerializable
22+
FixedString32Bytes m_Name;
2323
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
2424
{
2525
serializer.SerializeValue(ref m_Name);

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
66

77
Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com).
88

9-
## [v1.3.0-pre UNRELEASED] - yyyy-mm-dd
9+
## [v1.3.0-pre] - 2022-06-23
1010

1111
### Added
1212
* Adding RNSM (Runtime Network Stats Monitor) to boss room [MTT-3267] (#621)
@@ -22,7 +22,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
2222
* NetworkRigidbody-based toss Action, thrown by new VandalImp class [MTT-2333](#671)
2323

2424
### Changed
25-
* Bump NGO to pre.9 (#643)
25+
* Bump NGO to pre.10 (#678) --> Fix in Boss Room related to the connection approval breaking change. Removing useless ForceNetworkSerializeByMemcpy for player names.
2626
* Bump Boss Room to Unity 2021 [MTT-3022] (#620)
2727
* Remove initial ugs popup [MTT-3563] (#650) --> Users who do not use UGS will no longer receive a popup when starting the application telling them how to set it up. It is replaced with a tooltip that appears when hovering on the "Start with Lobby" button with the cursor.
2828
* Folders and assemblies refactor MTT-2623, MTT-2615 (#628) --> work in progress

Packages/com.unity.multiplayer.samples.coop/CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
# Multiplayer Samples Co-op Changelog
22

3-
## [Unreleased] - yyyy-mm-dd
3+
## [1.3.0-pre] - 2022-06-23
44

55
### Added
66
* feat: other players loading progress in loading screen [MTT-2239] (#580)
77
* feat: adding editor child scene loader for composed scenes (#653)
8+
* Added an assembly definition for the RNSM utilities so that they are only compiled if using Unity version 2021.2 or newer
89

910
### Changed
1011
*
1112
### Removed
1213
*
1314
### Fixed
14-
*
15+
* Fixed breaking change from NetworkTransform in ClientNetworkTransform
1516
## [1.2.0-pre] - 2022-04-28
1617
### Added
1718
* Client network transform move to samples [MTT-3406] (#629) --> You can now use Boss Room's Utilities package to import ClientNetworkTransform using this line in your manifest file

Packages/com.unity.multiplayer.samples.coop/Utilities/EditorChildSceneLoader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void Update()
2323

2424
public void SaveSceneSetup()
2525
{
26-
ChildScenesToLoadConfig ??= new();
26+
ChildScenesToLoadConfig ??= new List<SceneAsset>();
2727
ChildScenesToLoadConfig.Clear();
2828
foreach (var sceneSetup in EditorSceneManager.GetSceneManagerSetup())
2929
{
@@ -35,7 +35,7 @@ public void ResetSceneSetupToConfig()
3535
{
3636
var sceneAssetsToLoad = ChildScenesToLoadConfig;
3737

38-
List<SceneSetup> sceneSetupToLoad = new();
38+
List<SceneSetup> sceneSetupToLoad = new List<SceneSetup>();
3939
foreach (var sceneAsset in sceneAssetsToLoad)
4040
{
4141
sceneSetupToLoad.Add(new SceneSetup() { path = AssetDatabase.GetAssetPath(sceneAsset), isActive = false, isLoaded = true });

Packages/com.unity.multiplayer.samples.coop/Utilities/Net/ClientAuthority/ClientNetworkTransform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected override void Update()
4040
}
4141
}
4242

43-
protected override bool OnIsServerAuthoritatitive()
43+
protected override bool OnIsServerAuthoritative()
4444
{
4545
return false;
4646
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "Unity.Multiplayer.Samples.Utilities.RNSM",
3+
"rootNamespace": "",
4+
"references": [
5+
"GUID:2c360f3794ebc41388fc11424ddbfdd0"
6+
],
7+
"includePlatforms": [],
8+
"excludePlatforms": [],
9+
"allowUnsafeCode": false,
10+
"overrideReferences": false,
11+
"precompiledReferences": [],
12+
"autoReferenced": true,
13+
"defineConstraints": [
14+
"UNITY_2021_2_OR_NEWER"
15+
],
16+
"versionDefines": [],
17+
"noEngineReferences": false
18+
}

Packages/com.unity.multiplayer.samples.coop/Utilities/Net/RNSM/com.unity.multiplayer.samples.utilities.rnsm.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/com.unity.multiplayer.samples.coop/Utilities/SceneManagement/ClientLoadingScreen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ protected virtual void AddOtherPlayerProgressBar(ulong clientId, NetworkedLoadin
199199

200200
void RemoveOtherPlayerProgressBar(ulong clientId, NetworkedLoadingProgressTracker progressTracker = null)
201201
{
202-
if (progressTracker is not null)
202+
if (progressTracker != null)
203203
{
204204
progressTracker.Progress.OnValueChanged -= m_LoadingProgressBars[clientId].UpdateProgress;
205205
}

Packages/com.unity.multiplayer.samples.coop/Utilities/com.unity.multiplayer.samples.utilities.asmdef

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
"name": "Unity.Multiplayer.Samples.Utilities",
33
"rootNamespace": "",
44
"references": [
5-
"Unity.Netcode.Adapter.UTP",
65
"Unity.Netcode.Components",
76
"Unity.Netcode.Runtime",
87
"Unity.Services.Core",
98
"Unity.Services.Authentication",
10-
"Unity.Services.Relay",
11-
"Unity.Multiplayer.Tools.NetStatsMonitor.Component"
9+
"Unity.Services.Relay"
1210
],
1311
"includePlatforms": [],
1412
"excludePlatforms": [],
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
{
22
"name": "com.unity.multiplayer.samples.coop",
33
"displayName": "Multiplayer Samples Utilities",
4-
"version": "1.2.0-pre",
4+
"version": "1.3.0-pre",
55
"type": "template",
66
"host": "hub",
77
"unity": "2020.3",
88
"description": "Utilities package built on top of Netcode for GameObjects, providing useful scripts and tools.",
99
"dependencies": {
1010
"com.unity.learn.iet-framework": "1.2.1",
11-
"com.unity.netcode.gameobjects": "1.0.0-pre.8",
11+
"com.unity.multiplayer.tools": "1.0.0-pre.7",
12+
"com.unity.netcode.gameobjects": "1.0.0-pre.10",
1213
"com.unity.services.authentication": "1.0.0-pre.4",
1314
"com.unity.services.lobby": "1.0.0-pre.6",
14-
"com.unity.services.relay": "1.0.1-pre.5"
15+
"com.unity.services.relay": "1.0.2"
1516
}
16-
}
17+
}

Packages/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"com.unity.ide.vscode": "1.2.5",
1010
"com.unity.learn.iet-framework": "2.2.1",
1111
"com.unity.memoryprofiler": "0.5.0-preview.1",
12-
"com.unity.netcode.gameobjects": "1.0.0-pre.9",
12+
"com.unity.netcode.gameobjects": "1.0.0-pre.10",
1313
"com.unity.multiplayer.tools": "1.0.0-pre.7",
1414
"com.unity.postprocessing": "3.2.1",
1515
"com.unity.render-pipelines.universal": "12.1.6",

Packages/packages-lock.json

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"hash": "0fc6f532e4f47d66d173314efcb906bc7cf0d00f"
1717
},
1818
"com.unity.burst": {
19-
"version": "1.6.5",
20-
"depth": 1,
19+
"version": "1.6.6",
20+
"depth": 2,
2121
"source": "registry",
2222
"dependencies": {
2323
"com.unity.mathematics": "1.2.1"
@@ -41,11 +41,11 @@
4141
"url": "https://packages.unity.com"
4242
},
4343
"com.unity.collections": {
44-
"version": "1.2.3",
45-
"depth": 1,
44+
"version": "1.2.4",
45+
"depth": 2,
4646
"source": "registry",
4747
"dependencies": {
48-
"com.unity.burst": "1.6.4",
48+
"com.unity.burst": "1.6.6",
4949
"com.unity.test-framework": "1.1.31"
5050
},
5151
"url": "https://packages.unity.com"
@@ -121,10 +121,11 @@
121121
"source": "embedded",
122122
"dependencies": {
123123
"com.unity.learn.iet-framework": "1.2.1",
124-
"com.unity.netcode.gameobjects": "1.0.0-pre.8",
124+
"com.unity.multiplayer.tools": "1.0.0-pre.7",
125+
"com.unity.netcode.gameobjects": "1.0.0-pre.10",
125126
"com.unity.services.authentication": "1.0.0-pre.4",
126127
"com.unity.services.lobby": "1.0.0-pre.6",
127-
"com.unity.services.relay": "1.0.1-pre.5"
128+
"com.unity.services.relay": "1.0.2"
128129
}
129130
},
130131
"com.unity.multiplayer.tools": {
@@ -141,12 +142,12 @@
141142
"url": "https://packages.unity.com"
142143
},
143144
"com.unity.netcode.gameobjects": {
144-
"version": "1.0.0-pre.9",
145+
"version": "1.0.0-pre.10",
145146
"depth": 0,
146147
"source": "registry",
147148
"dependencies": {
148149
"com.unity.nuget.mono-cecil": "1.10.1",
149-
"com.unity.transport": "1.0.0"
150+
"com.unity.transport": "1.1.0"
150151
},
151152
"url": "https://packages.unity.com"
152153
},
@@ -352,13 +353,13 @@
352353
"url": "https://packages.unity.com"
353354
},
354355
"com.unity.transport": {
355-
"version": "1.0.0",
356+
"version": "1.1.0",
356357
"depth": 1,
357358
"source": "registry",
358359
"dependencies": {
359-
"com.unity.collections": "1.2.3",
360-
"com.unity.burst": "1.6.4",
361-
"com.unity.mathematics": "1.2.5"
360+
"com.unity.collections": "1.2.4",
361+
"com.unity.burst": "1.6.6",
362+
"com.unity.mathematics": "1.2.6"
362363
},
363364
"url": "https://packages.unity.com"
364365
},

0 commit comments

Comments
 (0)