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