Skip to content
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

breaking: Move connectionId to NetworkConnectionToClient #3970

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 0 additions & 12 deletions Assets/Mirror/Core/NetworkConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ public abstract class NetworkConnection
{
public const int LocalConnectionId = 0;

/// <summary>Unique identifier for this connection that is assigned by the transport layer.</summary>
// 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;

/// <summary>Flag that indicates the client has been authenticated.</summary>
public bool isAuthenticated;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -213,7 +203,5 @@ public virtual void Cleanup()
batcher.Clear();
}
}

public override string ToString() => $"connection({connectionId})";
}
}
13 changes: 11 additions & 2 deletions Assets/Mirror/Core/NetworkConnectionToClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public class NetworkConnectionToClient : NetworkConnection

public virtual string address { get; private set; }

/// <summary>Unique identifier for this connection that is assigned by the transport layer.</summary>
// 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;

/// <summary>NetworkIdentities that this connection can see</summary>
// TODO move to server's NetworkConnectionToClient?
public readonly HashSet<NetworkIdentity> observing = new HashSet<NetworkIdentity>();
Expand Down Expand Up @@ -50,9 +55,11 @@ public class NetworkConnectionToClient : NetworkConnection
/// <summary>Round trip time (in seconds) that it takes a message to go server->client->server.</summary>
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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirror/Core/NetworkIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading