From b3325e9c85a71ff7f99a031e26f042b22e95341f Mon Sep 17 00:00:00 2001 From: MrGadget <9826063+MrGadget1024@users.noreply.github.com> Date: Tue, 21 Jan 2025 07:52:21 -0500 Subject: [PATCH] breaking: Move connectionId to NetworkConnectionToClient - Only transports set connectionId - None of our transports set it on client side (NetworkConnectionToServer) - Some projects may be referencing NetworkConnection type instead of NetworkConnectionToClient and we can't obsolete connectionId in the base class - Requires fixing NI::RemoveObserver to correct type --- Assets/Mirror/Core/NetworkConnection.cs | 12 ------------ Assets/Mirror/Core/NetworkConnectionToClient.cs | 13 +++++++++++-- Assets/Mirror/Core/NetworkIdentity.cs | 2 +- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Assets/Mirror/Core/NetworkConnection.cs b/Assets/Mirror/Core/NetworkConnection.cs index 851beaea092..1268ca21597 100644 --- a/Assets/Mirror/Core/NetworkConnection.cs +++ b/Assets/Mirror/Core/NetworkConnection.cs @@ -10,11 +10,6 @@ public abstract class NetworkConnection { public const int LocalConnectionId = 0; - /// Unique identifier for this connection that is assigned by the transport layer. - // assigned by transport, this id is unique for every connection on server. - // clients don't know their own id and they don't know other client's ids. - public readonly int connectionId; - /// Flag that indicates the client has been authenticated. public bool isAuthenticated; @@ -68,11 +63,6 @@ internal NetworkConnection() lastMessageTime = Time.time; } - internal NetworkConnection(int networkConnectionId) : this() - { - connectionId = networkConnectionId; - } - // TODO if we only have Reliable/Unreliable, then we could initialize // two batches and avoid this code protected Batcher GetBatchForChannelId(int channelId) @@ -213,7 +203,5 @@ public virtual void Cleanup() batcher.Clear(); } } - - public override string ToString() => $"connection({connectionId})"; } } diff --git a/Assets/Mirror/Core/NetworkConnectionToClient.cs b/Assets/Mirror/Core/NetworkConnectionToClient.cs index 802e46874ac..d80749c13ed 100644 --- a/Assets/Mirror/Core/NetworkConnectionToClient.cs +++ b/Assets/Mirror/Core/NetworkConnectionToClient.cs @@ -16,6 +16,11 @@ public class NetworkConnectionToClient : NetworkConnection public virtual string address { get; private set; } + /// Unique identifier for this connection that is assigned by the transport layer. + // assigned by transport, this id is unique for every connection on server. + // clients don't know their own id and they don't know other client's ids. + public readonly int connectionId; + /// NetworkIdentities that this connection can see // TODO move to server's NetworkConnectionToClient? public readonly HashSet observing = new HashSet(); @@ -50,9 +55,11 @@ public class NetworkConnectionToClient : NetworkConnection /// Round trip time (in seconds) that it takes a message to go server->client->server. public double rtt => _rtt.Value; - public NetworkConnectionToClient(int networkConnectionId, string clientAddress = "localhost") - : base(networkConnectionId) + internal NetworkConnectionToClient() : base() { } + + public NetworkConnectionToClient(int networkConnectionId, string clientAddress = "localhost") : base() { + connectionId = networkConnectionId; address = clientAddress; // initialize EMA with 'emaDuration' seconds worth of history. @@ -65,6 +72,8 @@ public NetworkConnectionToClient(int networkConnectionId, string clientAddress = snapshotBufferSizeLimit = Mathf.Max((int)NetworkClient.snapshotSettings.bufferTimeMultiplier, snapshotBufferSizeLimit); } + public override string ToString() => $"connection({connectionId})"; + public void OnTimeSnapshot(TimeSnapshot snapshot) { // protect against ever growing buffer size attacks diff --git a/Assets/Mirror/Core/NetworkIdentity.cs b/Assets/Mirror/Core/NetworkIdentity.cs index 92fbae17abd..af60ef3d90b 100644 --- a/Assets/Mirror/Core/NetworkIdentity.cs +++ b/Assets/Mirror/Core/NetworkIdentity.cs @@ -1213,7 +1213,7 @@ internal void ClearAllComponentsDirtyBits() } // this is used when a connection is destroyed, since the "observers" property is read-only - internal void RemoveObserver(NetworkConnection conn) + internal void RemoveObserver(NetworkConnectionToClient conn) { observers.Remove(conn.connectionId); }