@@ -290,8 +290,77 @@ private void OnServerNewClientConnection(Connection connection, NetCodeConnectio
290290 InvokeOnTransportEvent ( NetworkEvent . Connect , ( ulong ) connection . NetworkId . Value , default , m_RealTimeProvider . RealTimeSinceStartup ) ;
291291 }
292292
293+ private const string InvalidRpcMessage = "An invalid RPC was received" ;
294+ private const string HandshakeTimeoutMessage = "The connection was closed because the handshake timed out." ;
295+ private const string ApprovalFailureMessage = "The connection was closed because the connection was not approved by the server." ;
296+ private const string ApprovalTimeoutMessage = "The connection was closed because the connection approval process timed out." ;
297+
298+ private string GetDisconnectMessageFromNetworkStreamDisconnectReason ( NetworkStreamDisconnectReason reason )
299+ {
300+ switch ( reason )
301+ {
302+ case NetworkStreamDisconnectReason . ConnectionClose :
303+ return UnityTransportNotificationHandler . DisconnectedMessage ;
304+ case NetworkStreamDisconnectReason . Timeout :
305+ return UnityTransportNotificationHandler . TimeoutMessage ;
306+ case NetworkStreamDisconnectReason . MaxConnectionAttempts :
307+ return UnityTransportNotificationHandler . MaxConnectionAttemptsMessage ;
308+ case NetworkStreamDisconnectReason . ClosedByRemote :
309+ return UnityTransportNotificationHandler . ClosedRemoteConnectionMessage ;
310+ case NetworkStreamDisconnectReason . BadProtocolVersion :
311+ return UnityTransportNotificationHandler . ProtocolErrorMessage ;
312+ case NetworkStreamDisconnectReason . InvalidRpc :
313+ return InvalidRpcMessage ;
314+ case NetworkStreamDisconnectReason . AuthenticationFailure :
315+ return UnityTransportNotificationHandler . AuthenticationFailureMessage ;
316+ case NetworkStreamDisconnectReason . ProtocolError :
317+ return UnityTransportNotificationHandler . ProtocolErrorMessage ;
318+ case NetworkStreamDisconnectReason . HandshakeTimeout :
319+ return HandshakeTimeoutMessage ;
320+ case NetworkStreamDisconnectReason . ApprovalFailure :
321+ return ApprovalFailureMessage ;
322+ case NetworkStreamDisconnectReason . ApprovalTimeout :
323+ return ApprovalTimeoutMessage ;
324+ }
325+ return "Unknown reason" ;
326+ }
327+
328+ private DisconnectEvents GetDisconnectEventFromNetworkStreamDisconnectReason ( NetworkStreamDisconnectReason reason )
329+ {
330+ switch ( reason )
331+ {
332+ case NetworkStreamDisconnectReason . ConnectionClose :
333+ return DisconnectEvents . Disconnected ;
334+ case NetworkStreamDisconnectReason . Timeout :
335+ return DisconnectEvents . ProtocolTimeout ;
336+ case NetworkStreamDisconnectReason . MaxConnectionAttempts :
337+ return DisconnectEvents . MaxConnectionAttempts ;
338+ case NetworkStreamDisconnectReason . ClosedByRemote :
339+ return DisconnectEvents . ClosedByRemote ;
340+ case NetworkStreamDisconnectReason . BadProtocolVersion :
341+ return DisconnectEvents . ProtocolError ;
342+ case NetworkStreamDisconnectReason . InvalidRpc :
343+ return DisconnectEvents . ProtocolError ;
344+ case NetworkStreamDisconnectReason . AuthenticationFailure :
345+ return DisconnectEvents . AuthenticationFailure ;
346+ case NetworkStreamDisconnectReason . ProtocolError :
347+ return DisconnectEvents . ProtocolError ;
348+ case NetworkStreamDisconnectReason . HandshakeTimeout :
349+ return DisconnectEvents . ProtocolError ;
350+ case NetworkStreamDisconnectReason . ApprovalFailure :
351+ return DisconnectEvents . AuthenticationFailure ;
352+ case NetworkStreamDisconnectReason . ApprovalTimeout :
353+ return DisconnectEvents . ProtocolTimeout ;
354+ }
355+ return DisconnectEvents . Disconnected ;
356+ }
357+
293358 private void OnClientDisconnectFromServer ( Connection connection , NetCodeConnectionEvent connectionEvent )
294359 {
360+ SetDisconnectEvent (
361+ GetDisconnectEventFromNetworkStreamDisconnectReason ( connectionEvent . DisconnectReason ) ,
362+ GetDisconnectMessageFromNetworkStreamDisconnectReason ( connectionEvent . DisconnectReason )
363+ ) ;
295364 InvokeOnTransportEvent ( NetworkEvent . Disconnect , ( ulong ) connection . NetworkId . Value , default , m_RealTimeProvider . RealTimeSinceStartup ) ;
296365 }
297366
0 commit comments