diff --git a/Facepunch.Steamworks.Test/NetworkingSockets.cs b/Facepunch.Steamworks.Test/NetworkingSockets.cs index 597a155..80e05bb 100644 --- a/Facepunch.Steamworks.Test/NetworkingSockets.cs +++ b/Facepunch.Steamworks.Test/NetworkingSockets.cs @@ -54,8 +54,7 @@ public async Task ConnectToRelayServer() connection.UserData = 69; // Give it a second for something to happen - await Task.Delay( 5000 ); - + await Task.Delay( 1000 ); connection.Close(); diff --git a/Facepunch.Steamworks/Generated/Interfaces/ISteamNetworkingSockets.cs b/Facepunch.Steamworks/Generated/Interfaces/ISteamNetworkingSockets.cs index 960c602..3271fd7 100644 --- a/Facepunch.Steamworks/Generated/Interfaces/ISteamNetworkingSockets.cs +++ b/Facepunch.Steamworks/Generated/Interfaces/ISteamNetworkingSockets.cs @@ -216,11 +216,11 @@ internal int ReceiveMessagesOnListenSocket( Socket hSocket, [In,Out] ref SteamNe #region FunctionMeta [UnmanagedFunctionPointer( CallingConvention.ThisCall )] [return: MarshalAs( UnmanagedType.I1 )] - private delegate bool FGetConnectionInfo( IntPtr self, NetConnection hConn, ref SteamNetConnectionInfo_t pInfo ); + private delegate bool FGetConnectionInfo( IntPtr self, NetConnection hConn, ref ConnectionInfo pInfo ); private FGetConnectionInfo _GetConnectionInfo; #endregion - internal bool GetConnectionInfo( NetConnection hConn, ref SteamNetConnectionInfo_t pInfo ) + internal bool GetConnectionInfo( NetConnection hConn, ref ConnectionInfo pInfo ) { return _GetConnectionInfo( Self, hConn, ref pInfo ); } diff --git a/Facepunch.Steamworks/Generated/SteamStructs.cs b/Facepunch.Steamworks/Generated/SteamStructs.cs index 6f13f06..f0846bb 100644 --- a/Facepunch.Steamworks/Generated/SteamStructs.cs +++ b/Facepunch.Steamworks/Generated/SteamStructs.cs @@ -12136,7 +12136,7 @@ public struct Pack8 internal struct SteamNetConnectionStatusChangedCallback_t { internal NetConnection Conn; // m_hConn HSteamNetConnection - internal SteamNetConnectionInfo_t Nfo; // m_info SteamNetConnectionInfo_t + internal ConnectionInfo Nfo; // m_info SteamNetConnectionInfo_t internal SteamNetworkingConnectionState OldState; // m_eOldState ESteamNetworkingConnectionState #region SteamCallback @@ -12191,7 +12191,7 @@ public static void Install( Action ac public struct Pack8 { internal NetConnection Conn; // m_hConn HSteamNetConnection - internal SteamNetConnectionInfo_t Nfo; // m_info SteamNetConnectionInfo_t + internal ConnectionInfo Nfo; // m_info SteamNetConnectionInfo_t internal SteamNetworkingConnectionState OldState; // m_eOldState ESteamNetworkingConnectionState public static implicit operator SteamNetConnectionStatusChangedCallback_t ( SteamNetConnectionStatusChangedCallback_t.Pack8 d ) => new SteamNetConnectionStatusChangedCallback_t{ Conn = d.Conn,Nfo = d.Nfo,OldState = d.OldState, }; diff --git a/Facepunch.Steamworks/SteamNetworkingSockets.cs b/Facepunch.Steamworks/SteamNetworkingSockets.cs index b3a3774..84c6a54 100644 --- a/Facepunch.Steamworks/SteamNetworkingSockets.cs +++ b/Facepunch.Steamworks/SteamNetworkingSockets.cs @@ -37,13 +37,44 @@ internal static void InstallEvents() private static void OnConnectionStatusChanged( SteamNetConnectionStatusChangedCallback_t data ) { + if ( data.Nfo.state != data.OldState ) + { + OnConnectionStateChanged( data ); + } + Console.WriteLine( $"data.Conn: {data.Conn.ToString()}" ); Console.WriteLine( $"data.Conn.UserData: {data.Conn.UserData}" ); Console.WriteLine( $"data.Conn.ConnectionName: {data.Conn.ConnectionName}" ); - Console.WriteLine( $"States: {data.Nfo.state} {data.OldState}" ); + Console.WriteLine( $"identity: {data.Nfo.identity}" ); + Console.WriteLine( $"identity.type: {data.Nfo.identity.type}" ); + Console.WriteLine( $"identity.m_cbSize: {data.Nfo.identity.m_cbSize}" ); + Console.WriteLine( $"identity.steamID: {data.Nfo.identity.steamID}" ); + Console.WriteLine( $"userData: {data.Nfo.userData}" ); + Console.WriteLine( $"listenSocket: {data.Nfo.listenSocket}" ); + Console.WriteLine( $"address: {data.Nfo.address}" ); + Console.WriteLine( $"popRemote: {data.Nfo.popRemote}" ); + Console.WriteLine( $"popRelay: {data.Nfo.popRelay}" ); + Console.WriteLine( $"state: {data.Nfo.state}" ); + Console.WriteLine( $"endReason: {data.Nfo.endReason}" ); + Console.WriteLine( $"endDebug: {data.Nfo.endDebug}" ); + Console.WriteLine( $"connectionDescription: {data.Nfo.connectionDescription}" ); + Console.WriteLine( $"---" ); } + private static void OnConnectionStateChanged( SteamNetConnectionStatusChangedCallback_t data ) + { + switch ( data.Nfo.state ) + { + case SteamNetworkingConnectionState.Connecting: + OnConnecting?.Invoke( data.Conn, data.Nfo ); + return; + } + } + + public static event Action OnConnecting; + + /// /// Creates a "server" socket that listens for clients to connect to by calling /// Connect, over ordinary UDP (IPv4 or IPv6) diff --git a/Facepunch.Steamworks/Structs/ConnectionInfo.cs b/Facepunch.Steamworks/Structs/ConnectionInfo.cs new file mode 100644 index 0000000..cc4e9fd --- /dev/null +++ b/Facepunch.Steamworks/Structs/ConnectionInfo.cs @@ -0,0 +1,22 @@ +using System.Runtime.InteropServices; + +namespace Steamworks.Data +{ + [StructLayout( LayoutKind.Sequential, Pack = 0 )] + public struct ConnectionInfo + { + internal NetworkIdentity identity; + internal long userData; + internal Socket listenSocket; + internal NetworkAddress address; + internal ushort pad; + internal SteamNetworkingPOPID popRemote; + internal SteamNetworkingPOPID popRelay; + internal SteamNetworkingConnectionState state; + internal int endReason; + [MarshalAs( UnmanagedType.ByValTStr, SizeConst = 128 )] + internal string endDebug; + [MarshalAs( UnmanagedType.ByValTStr, SizeConst = 128 )] + internal string connectionDescription; + } +} \ No newline at end of file diff --git a/Facepunch.Steamworks/Structs/NetConnection.cs b/Facepunch.Steamworks/Structs/NetConnection.cs index f3734cf..9f5afa1 100644 --- a/Facepunch.Steamworks/Structs/NetConnection.cs +++ b/Facepunch.Steamworks/Structs/NetConnection.cs @@ -5,17 +5,7 @@ namespace Steamworks.Data { public struct NetConnection { - uint Id; - - public static implicit operator NetConnection( uint value ) - { - return new NetConnection { Id = value }; - } - - public static implicit operator uint( NetConnection value ) - { - return value.Id; - } + internal uint Id; public override string ToString() => Id.ToString(); diff --git a/Facepunch.Steamworks/Structs/NetworkAddress.cs b/Facepunch.Steamworks/Structs/NetworkAddress.cs index 25830eb..67edf0e 100644 --- a/Facepunch.Steamworks/Structs/NetworkAddress.cs +++ b/Facepunch.Steamworks/Structs/NetworkAddress.cs @@ -2,7 +2,7 @@ namespace Steamworks.Data { - [StructLayout( LayoutKind.Explicit )] + [StructLayout( LayoutKind.Explicit, Size = 18 )] public struct NetworkAddress { [FieldOffset( 0 )] diff --git a/Facepunch.Steamworks/Structs/NetworkIdentity.cs b/Facepunch.Steamworks/Structs/NetworkIdentity.cs index 2c8af45..d2b55b2 100644 --- a/Facepunch.Steamworks/Structs/NetworkIdentity.cs +++ b/Facepunch.Steamworks/Structs/NetworkIdentity.cs @@ -2,7 +2,7 @@ namespace Steamworks.Data { - [StructLayout( LayoutKind.Explicit, Size = 136 )] + [StructLayout( LayoutKind.Explicit, Size = 136, Pack = 8 )] public struct NetworkIdentity { [FieldOffset( 0 )] diff --git a/Facepunch.Steamworks/Structs/SteamNetworking.cs b/Facepunch.Steamworks/Structs/SteamNetworking.cs index a297d98..0232250 100644 --- a/Facepunch.Steamworks/Structs/SteamNetworking.cs +++ b/Facepunch.Steamworks/Structs/SteamNetworking.cs @@ -72,24 +72,6 @@ public void Destroy() }*/ } - [StructLayout( LayoutKind.Sequential )] - public struct SteamNetConnectionInfo_t - { - public NetworkIdentity identity; - public long userData; - public Socket listenSocket; - public NetworkAddress address; - private ushort pad; - private SteamNetworkingPOPID popRemote; - private SteamNetworkingPOPID popRelay; - public SteamNetworkingConnectionState state; - public int endReason; - [MarshalAs( UnmanagedType.ByValTStr, SizeConst = 128 )] - public string endDebug; - [MarshalAs( UnmanagedType.ByValTStr, SizeConst = 128 )] - public string connectionDescription; - } - [StructLayout( LayoutKind.Sequential )] public struct SteamNetworkingQuickConnectionStatus { diff --git a/Generator/Cleanup.cs b/Generator/Cleanup.cs index 53792fe..ef1cb07 100644 --- a/Generator/Cleanup.cs +++ b/Generator/Cleanup.cs @@ -34,6 +34,7 @@ public static string ConvertType( string type ) type = type.Replace( "HSteamListenSocket", "Socket" ); type = type.Replace( "SteamNetworkingIPAddr", "NetworkAddress" ); type = type.Replace( "SteamNetworkingIdentity", "NetworkIdentity" ); + type = type.Replace( "SteamNetConnectionInfo_t", "ConnectionInfo" ); return type; } diff --git a/Generator/CodeWriter/Types/BaseType.cs b/Generator/CodeWriter/Types/BaseType.cs index 04d31da..24a791b 100644 --- a/Generator/CodeWriter/Types/BaseType.cs +++ b/Generator/CodeWriter/Types/BaseType.cs @@ -49,9 +49,9 @@ public static BaseType Parse( string type, string varname = null ) if ( basicType == "InventoryItemId" ) return new StructType { NativeType = type, VarName = varname, StructName = basicType }; if ( basicType == "InventoryDefId" ) return new StructType { NativeType = type, VarName = varname, StructName = basicType }; if ( basicType == "PingLocation" ) return new StructType { NativeType = type, VarName = varname, StructName = basicType }; - if ( basicType == "SteamNetworkingIPAddr" ) return new StructType { NativeType = type, VarName = varname, StructName = basicType }; if ( basicType == "NetworkIdentity" ) return new StructType { NativeType = type, VarName = varname, StructName = basicType }; if ( basicType == "NetworkAddress" ) return new StructType { NativeType = type, VarName = varname, StructName = basicType }; + if ( basicType == "ConnectionInfo" ) return new StructType { NativeType = type, VarName = varname, StructName = basicType }; if ( basicType.StartsWith( "E" ) && char.IsUpper( basicType[1] ) ) return new EnumType { NativeType = type.Substring( 1 ), VarName = varname }; return new BaseType { NativeType = type, VarName = varname };