diff --git a/Facepunch.Steamworks/Networking/ISocketManager.cs b/Facepunch.Steamworks/Networking/ISocketManager.cs index faab31d..44d6797 100644 --- a/Facepunch.Steamworks/Networking/ISocketManager.cs +++ b/Facepunch.Steamworks/Networking/ISocketManager.cs @@ -16,7 +16,7 @@ namespace Steamworks void OnConnected( Connection connection, ConnectionInfo info ); /// - /// Called when the connection leaves + /// Called when the connection leaves. Must call Close on the connection /// void OnDisconnected( Connection connection, ConnectionInfo info ); diff --git a/Facepunch.Steamworks/Networking/SocketManager.cs b/Facepunch.Steamworks/Networking/SocketManager.cs index 5c585fa..fd73550 100644 --- a/Facepunch.Steamworks/Networking/SocketManager.cs +++ b/Facepunch.Steamworks/Networking/SocketManager.cs @@ -50,6 +50,7 @@ namespace Steamworks if ( !Connecting.Contains( connection ) ) { Connecting.Add( connection ); + OnConnecting( connection, info ); } break; @@ -67,6 +68,9 @@ namespace Steamworks case ConnectionState.None: if ( Connecting.Contains( connection ) || Connected.Contains( connection ) ) { + Connecting.Remove( connection ); + Connected.Remove( connection ); + OnDisconnected( connection, info ); } break; @@ -81,7 +85,6 @@ namespace Steamworks if ( Interface != null ) { Interface.OnConnecting( connection, info ); - return; } else { @@ -106,12 +109,14 @@ namespace Steamworks { SteamNetworkingSockets.Internal.SetConnectionPollGroup( connection, 0 ); - connection.Close(); - - Connecting.Remove( connection ); - Connected.Remove( connection ); - - Interface?.OnDisconnected( connection, info ); + if ( Interface != null ) + { + Interface.OnDisconnected( connection, info ); + } + else + { + connection.Close(); + } } public void Receive( int bufferSize = 32 )