Skip to content

Commit a7745cb

Browse files
update
Adding additional comments and disconnect event specific messages for UnityTransport.
1 parent 486ab1c commit a7745cb

File tree

2 files changed

+55
-10
lines changed

2 files changed

+55
-10
lines changed

com.unity.netcode.gameobjects/Runtime/Transports/NetworkTransport.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,20 +166,57 @@ internal NetworkTopologyTypes CurrentTopology()
166166
return OnCurrentTopology();
167167
}
168168

169-
169+
/// <summary>
170+
/// The Netcode for GameObjects standardized disconnection event types.
171+
/// </summary>
172+
/// <remarks>
173+
/// <see cref="AddDisconnectEventMap"/> provides you with the ability to register the transport's disconnect event types with the local equivalent.
174+
/// </remarks>
170175
public enum DisconnectEvents : byte
171176
{
177+
/// <summary>
178+
/// If transport has mapped its disconnect events, this event signifies that the transport closed the connection due to a locally invoked shutdown.
179+
/// </summary>
172180
TransportShutdown,
181+
/// <summary>
182+
/// If transport has mapped its disconnect events, this event signifies a graceful disconnect.
183+
/// </summary>
173184
Disconnected,
185+
/// <summary>
186+
/// If transport has mapped its disconnect events, this event signifies that the transport's connection to the endpoint has timed out and the connection was closed.
187+
/// </summary>
174188
ProtocolTimeout,
189+
/// <summary>
190+
/// If transport has mapped its disconnect events, this event signifies that the disconnect is due to the maximum number of failed connection attempts has been reached.
191+
/// </summary>
175192
MaxConnectionAttempts,
193+
/// <summary>
194+
/// If transport has mapped its disconnect events, this event signifies that the remote endpoint closed the connection.
195+
/// </summary>
176196
ClosedByRemote,
197+
/// <summary>
198+
/// If transport has mapped its disconnect events, this event signifies the local transport closed the incoming remote endpoint connection.
199+
/// </summary>
177200
ClosedRemoteConnection,
201+
/// <summary>
202+
/// If transport has mapped its disconnect events, this event signifies that the connection was closed due to an authentication failure.
203+
/// </summary>
178204
AuthenticationFailure,
205+
/// <summary>
206+
/// If transport has mapped its disconnect events, this event signifies that a lower-level (unkown) transport error occurred.
207+
/// </summary>
179208
ProtocolError,
180209
}
181210

211+
/// <summary>
212+
/// If the transport has implemented disconnection event mapping, then this will be set to the most recent disconnection event.
213+
/// </summary>
182214
public DisconnectEvents DisconnectEvent { get; private set; }
215+
216+
/// <summary>
217+
/// If the transport has implemented disconnection event mapping and disconnection event message mapping, then this will contain
218+
/// the transport specific message associated with the disconnect event type.
219+
/// </summary>
183220
public string DisconnectEventMessage { get; private set; }
184221

185222
private Dictionary<byte, DisconnectEvents> m_DisconnectEventMap = new Dictionary<byte, DisconnectEvents>();

com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
using Unity.Networking.Transport.Relay;
2020
using Unity.Networking.Transport.TLS;
2121
using Unity.Networking.Transport.Utilities;
22-
using UnityEditor.PackageManager;
2322
using UnityEngine;
2423

2524
using NetcodeEvent = Unity.Netcode.NetworkEvent;
@@ -1371,21 +1370,30 @@ public override void DisconnectRemoteClient(ulong clientId)
13711370
private const byte k_ClosedRemoteConnection = 128;
13721371
private const byte k_TransportShutdown = 129;
13731372

1373+
internal const string DisconnectedMessage = "Gracefully disconnected.";
1374+
internal const string TimeoutMessage = "Connection closed due to timed out.";
1375+
internal const string MaxConnectionAttemptsMessage = "Connection closed due to maximum connection attempts reached.";
1376+
internal const string ClosedByRemoteMessage = "Connection was closed by remote endpoint.";
1377+
internal const string AuthenticationFailureMessage = "Connection closed due to authentication failure.";
1378+
internal const string ProtocolErrorMessage = "Gracefully disconnected.";
1379+
internal const string ClosedRemoteConnectionMessage = "Local transport closed the remote endpoint connection.";
1380+
internal const string TransportShutdownMessage = "The transport was shutdown.";
1381+
13741382
/// <inheritdoc/>
13751383
protected override void OnCreateDisconnectEventMap()
13761384
{
13771385
// Implemented in UTP
13781386

1379-
AddDisconnectEventMap(DisconnectEvents.Disconnected, (byte)DisconnectReason.Default, "Gracefully disconnected.");
1380-
AddDisconnectEventMap(DisconnectEvents.ProtocolTimeout, (byte)DisconnectReason.Timeout, "Connection timed out.");
1381-
AddDisconnectEventMap(DisconnectEvents.MaxConnectionAttempts, (byte)DisconnectReason.MaxConnectionAttempts, "Maximum connection attempts reached.");
1382-
AddDisconnectEventMap(DisconnectEvents.ClosedByRemote, (byte)DisconnectReason.ClosedByRemote, "Remote connection was closed.");
1383-
AddDisconnectEventMap(DisconnectEvents.AuthenticationFailure, (byte)DisconnectReason.AuthenticationFailure, "Authentication failed.");
1384-
AddDisconnectEventMap(DisconnectEvents.ProtocolError, (byte)DisconnectReason.ProtocolError, "Transport protocol error encountered.");
1387+
AddDisconnectEventMap(DisconnectEvents.Disconnected, (byte)DisconnectReason.Default, DisconnectedMessage);
1388+
AddDisconnectEventMap(DisconnectEvents.ProtocolTimeout, (byte)DisconnectReason.Timeout, TimeoutMessage);
1389+
AddDisconnectEventMap(DisconnectEvents.MaxConnectionAttempts, (byte)DisconnectReason.MaxConnectionAttempts, MaxConnectionAttemptsMessage);
1390+
AddDisconnectEventMap(DisconnectEvents.ClosedByRemote, (byte)DisconnectReason.ClosedByRemote, ClosedByRemoteMessage);
1391+
AddDisconnectEventMap(DisconnectEvents.AuthenticationFailure, (byte)DisconnectReason.AuthenticationFailure, AuthenticationFailureMessage);
1392+
AddDisconnectEventMap(DisconnectEvents.ProtocolError, (byte)DisconnectReason.ProtocolError, ProtocolErrorMessage);
13851393

13861394
// Not implemented in UTP
1387-
AddDisconnectEventMap(DisconnectEvents.ClosedRemoteConnection, k_ClosedRemoteConnection, "Local transport closed the remote connection.");
1388-
AddDisconnectEventMap(DisconnectEvents.TransportShutdown, k_TransportShutdown, "The transport was shutdown.");
1395+
AddDisconnectEventMap(DisconnectEvents.ClosedRemoteConnection, k_ClosedRemoteConnection, ClosedRemoteConnectionMessage);
1396+
AddDisconnectEventMap(DisconnectEvents.TransportShutdown, k_TransportShutdown, TransportShutdownMessage);
13891397

13901398
base.OnCreateDisconnectEventMap();
13911399
}

0 commit comments

Comments
 (0)