Skip to content

feat: bumping to pre.10 #678

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
merged 14 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,26 +161,27 @@ public bool AreAllClientsInServerScene()
}

/// <summary>
/// This logic plugs into the "ConnectionApprovalCallback" exposed by Netcode.NetworkManager, and is run every time a client connects to us.
/// See ClientGameNetPortal.StartClient for the complementary logic that runs when the client starts its connection.
/// This logic plugs into the "ConnectionApprovalResponse" exposed by Netcode.NetworkManager. It is run every time a client connects to us.
/// The complementary logic that runs when the client starts its connection can be found in ClientGameNetPortal.StartClient.
/// </summary>
/// <remarks>
/// Since our game doesn't have to interact with some third party authentication service to validate the identity of the new connection, our ApprovalCheck
/// method is simple, and runs synchronously, invoking "callback" to signal approval at the end of the method. Netcode currently doesn't support the ability
/// 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
/// custom message in the same channel that Netcode uses for its connection callback. Since the delivery is NetworkDelivery.ReliableSequenced, we can be
/// confident that our login result message will execute before any disconnect message.
/// 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
/// also send custom messages to connecting users before they receive their connection result (this is useful to set status messages client side
/// when connection is refused, for example).
/// </remarks>
/// <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>
/// <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>
/// <param name="connectionApprovedCallback">The delegate we must invoke to signal that the connection was approved or not. </param>
void ApprovalCheck(byte[] connectionData, ulong clientId, NetworkManager.ConnectionApprovedDelegate connectionApprovedCallback)
///
/// <param name="request"> The initial request contains, among other things, 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 name="response"> Our response to the approval process. In case of connection refusal with custom return message, we delay using the Pending field.
void ApprovalCheck(NetworkManager.ConnectionApprovalRequest request, NetworkManager.ConnectionApprovalResponse response)
{
var connectionData = request.Payload;
var clientId = request.ClientNetworkId;
if (connectionData.Length > k_MaxConnectPayload)
{
// If connectionData too high, deny immediately to avoid wasting time on the server. This is intended as
// a bit of light protection against DOS attacks that rely on sending silly big buffers of garbage.
connectionApprovedCallback(false, 0, false, null, null);
response.Approved = false;
return;
}

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

connectionApprovedCallback(true, null, true, null, null);
response.Approved = true;
response.CreatePlayerObject = true;
return;
}

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

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

// connection approval will create a player object for you
connectionApprovedCallback(true, null, true, Vector3.zero, Quaternion.identity);

m_ConnectionEventPublisher.Publish(new ConnectionEventMessage() { ConnectStatus = ConnectStatus.Success, PlayerName = SessionManager<SessionPlayerData>.Instance.GetPlayerData(clientId)?.PlayerName });
response.Approved = true;
response.CreatePlayerObject = true;
response.Position = Vector3.zero;
response.Rotation = Quaternion.identity;
return;
}
else

// In order for clients to not just get disconnected with no feedback, the server needs to tell the client why it disconnected it.
// This could happen after an auth check on a service or because of gameplay reasons (server full, wrong build version, etc)
// Since network objects haven't synced yet (still in the approval process), we need to send a custom message to clients, wait for
// UTP to update a frame and flush that message, then give our response to NetworkManager's connection approval process, with a denied approval.
IEnumerator WaitToDenyApproval(NetworkManager.ConnectionApprovalResponse response)
{
//TODO-FIXME:Netcode Issue #796. We should be able to send a reason and disconnect without a coroutine delay.
//TODO:Netcode: In the future we expect Netcode to allow us to return more information as part of the
//approval callback, so that we can provide more context on a reject. In the meantime we must provide
//the extra information ourselves, and then wait a short time before manually close down the connection.
response.Pending = true; // give some time for server to send connection status message to clients
response.Approved = false;
SendServerToClientConnectResult(clientId, gameReturnStatus);
SendServerToClientSetDisconnectReason(clientId, gameReturnStatus);
StartCoroutine(WaitToDenyApproval(connectionApprovedCallback));
if (m_LobbyServiceFacade.CurrentUnityLobby != null)
{
m_LobbyServiceFacade.RemovePlayerFromLobbyAsync(connectionPayload.playerId, m_LobbyServiceFacade.CurrentUnityLobby.Id);
}
yield return null; // wait a frame so UTP can flush it's messages on next update
response.Pending = false; // connection approval process can be finished.
}

StartCoroutine(WaitToDenyApproval(response));
if (m_LobbyServiceFacade.CurrentUnityLobby != null)
{
m_LobbyServiceFacade.RemovePlayerFromLobbyAsync(connectionPayload.playerId, m_LobbyServiceFacade.CurrentUnityLobby.Id);
}
}

ConnectStatus GetConnectStatus(ConnectionPayload connectionPayload)
ConnectStatus CanClientConnect(ConnectionPayload connectionPayload)
{
if (m_Portal.NetManager.ConnectedClientsIds.Count >= CharSelectData.k_MaxLobbyPlayers)
{
Expand All @@ -240,14 +250,7 @@ ConnectStatus GetConnectStatus(ConnectionPayload connectionPayload)
return ConnectStatus.IncompatibleBuildType;
}

return SessionManager<SessionPlayerData>.Instance.IsDuplicateConnection(connectionPayload.playerId) ?
ConnectStatus.LoggedInAgain : ConnectStatus.Success;
}

static IEnumerator WaitToDenyApproval(NetworkManager.ConnectionApprovedDelegate connectionApprovedCallback)
{
yield return new WaitForSeconds(0.5f);
connectionApprovedCallback(false, 0, false, null, null);
return SessionManager<SessionPlayerData>.Instance.IsDuplicateConnection(connectionPayload.playerId) ? ConnectStatus.LoggedInAgain : ConnectStatus.Success;
}

IEnumerator WaitToShutdown()
Expand Down Expand Up @@ -310,4 +313,4 @@ void ServerStartedHandler()
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class NetworkNameState : NetworkBehaviour
/// </summary>
public struct FixedPlayerName : INetworkSerializable
{
ForceNetworkSerializeByMemcpy<FixedString32Bytes> m_Name; // using ForceNetworkSerializeByMemcpy to force compatibility between FixedString and NetworkSerializable
FixedString32Bytes m_Name;
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
{
serializer.SerializeValue(ref m_Name);
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
* Updated boss room's root scene to automatically load child scenes at editor time (#653)

### Changed
* Bump NGO to pre.9 (#643)
* Bump NGO to pre.10 (#678) --> Fix in Boss Room related to the connection approval breaking change. Removing useless ForceNetworkSerializeByMemcpy for player names.
* Bump Boss Room to Unity 2021 [MTT-3022] (#620)
* 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.
* Folders and assemblies refactor MTT-2623, MTT-2615 (#628) --> work in progress
Expand Down
2 changes: 1 addition & 1 deletion Packages/com.unity.multiplayer.samples.coop/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
### Removed
*
### Fixed
*
* Fixed breaking change from NetworkTransform in ClientNetworkTransform
## [1.2.0-pre] - 2022-04-28
### Added
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void Update()

public void SaveSceneSetup()
{
ChildScenesToLoadConfig ??= new();
ChildScenesToLoadConfig ??= new List<SceneAsset>();
ChildScenesToLoadConfig.Clear();
foreach (var sceneSetup in EditorSceneManager.GetSceneManagerSetup())
{
Expand All @@ -35,7 +35,7 @@ public void ResetSceneSetupToConfig()
{
var sceneAssetsToLoad = ChildScenesToLoadConfig;

List<SceneSetup> sceneSetupToLoad = new();
List<SceneSetup> sceneSetupToLoad = new List<SceneSetup>();
foreach (var sceneAsset in sceneAssetsToLoad)
{
sceneSetupToLoad.Add(new SceneSetup() { path = AssetDatabase.GetAssetPath(sceneAsset), isActive = false, isLoaded = true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected override void Update()
}
}

protected override bool OnIsServerAuthoritatitive()
protected override bool OnIsServerAuthoritative()
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ protected virtual void AddOtherPlayerProgressBar(ulong clientId, NetworkedLoadin

void RemoveOtherPlayerProgressBar(ulong clientId, NetworkedLoadingProgressTracker progressTracker = null)
{
if (progressTracker is not null)
if (progressTracker != null)
{
progressTracker.Progress.OnValueChanged -= m_LoadingProgressBars[clientId].UpdateProgress;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "Unity.Multiplayer.Samples.Utilities",
"rootNamespace": "",
"references": [
"Unity.Netcode.Adapter.UTP",
"Unity.Netcode.Components",
"Unity.Netcode.Runtime",
"Unity.Services.Core",
Expand Down
9 changes: 5 additions & 4 deletions Packages/com.unity.multiplayer.samples.coop/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "com.unity.multiplayer.samples.coop",
"displayName": "Multiplayer Samples Utilities",
"version": "1.2.0-pre",
"version": "1.3.0-pre",
"type": "template",
"host": "hub",
"unity": "2020.3",
"description": "Utilities package built on top of Netcode for GameObjects, providing useful scripts and tools.",
"dependencies": {
"com.unity.learn.iet-framework": "1.2.1",
"com.unity.netcode.gameobjects": "1.0.0-pre.8",
"com.unity.multiplayer.tools": "1.0.0-pre.7",
"com.unity.netcode.gameobjects": "1.0.0-pre.10",
"com.unity.services.authentication": "1.0.0-pre.4",
"com.unity.services.lobby": "1.0.0-pre.6",
"com.unity.services.relay": "1.0.1-pre.5"
"com.unity.services.relay": "1.0.2"
}
}
}
2 changes: 1 addition & 1 deletion Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"com.unity.ide.vscode": "1.2.5",
"com.unity.learn.iet-framework": "2.2.1",
"com.unity.memoryprofiler": "0.5.0-preview.1",
"com.unity.netcode.gameobjects": "1.0.0-pre.9",
"com.unity.netcode.gameobjects": "1.0.0-pre.10",
"com.unity.multiplayer.tools": "1.0.0-pre.7",
"com.unity.postprocessing": "3.2.1",
"com.unity.render-pipelines.universal": "12.1.6",
Expand Down
27 changes: 14 additions & 13 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"hash": "0fc6f532e4f47d66d173314efcb906bc7cf0d00f"
},
"com.unity.burst": {
"version": "1.6.5",
"depth": 1,
"version": "1.6.6",
"depth": 2,
"source": "registry",
"dependencies": {
"com.unity.mathematics": "1.2.1"
Expand All @@ -41,11 +41,11 @@
"url": "https://packages.unity.com"
},
"com.unity.collections": {
"version": "1.2.3",
"depth": 1,
"version": "1.2.4",
"depth": 2,
"source": "registry",
"dependencies": {
"com.unity.burst": "1.6.4",
"com.unity.burst": "1.6.6",
"com.unity.test-framework": "1.1.31"
},
"url": "https://packages.unity.com"
Expand Down Expand Up @@ -121,10 +121,11 @@
"source": "embedded",
"dependencies": {
"com.unity.learn.iet-framework": "1.2.1",
"com.unity.netcode.gameobjects": "1.0.0-pre.8",
"com.unity.multiplayer.tools": "1.0.0-pre.7",
"com.unity.netcode.gameobjects": "1.0.0-pre.10",
"com.unity.services.authentication": "1.0.0-pre.4",
"com.unity.services.lobby": "1.0.0-pre.6",
"com.unity.services.relay": "1.0.1-pre.5"
"com.unity.services.relay": "1.0.2"
}
},
"com.unity.multiplayer.tools": {
Expand All @@ -141,12 +142,12 @@
"url": "https://packages.unity.com"
},
"com.unity.netcode.gameobjects": {
"version": "1.0.0-pre.9",
"version": "1.0.0-pre.10",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.nuget.mono-cecil": "1.10.1",
"com.unity.transport": "1.0.0"
"com.unity.transport": "1.1.0"
},
"url": "https://packages.unity.com"
},
Expand Down Expand Up @@ -352,13 +353,13 @@
"url": "https://packages.unity.com"
},
"com.unity.transport": {
"version": "1.0.0",
"version": "1.1.0",
"depth": 1,
"source": "registry",
"dependencies": {
"com.unity.collections": "1.2.3",
"com.unity.burst": "1.6.4",
"com.unity.mathematics": "1.2.5"
"com.unity.collections": "1.2.4",
"com.unity.burst": "1.6.6",
"com.unity.mathematics": "1.2.6"
},
"url": "https://packages.unity.com"
},
Expand Down