ConnectionInfo

This commit is contained in:
Garry Newman 2019-05-02 21:40:39 +01:00
parent ce3525bf1d
commit 6be5826f31
11 changed files with 64 additions and 39 deletions

View File

@ -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();

View File

@ -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 );
}

View File

@ -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<SteamNetConnectionStatusChangedCallback_t> 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, };

View File

@ -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<NetConnection, ConnectionInfo> OnConnecting;
/// <summary>
/// Creates a "server" socket that listens for clients to connect to by calling
/// Connect, over ordinary UDP (IPv4 or IPv6)

View File

@ -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;
}
}

View File

@ -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();

View File

@ -2,7 +2,7 @@
namespace Steamworks.Data
{
[StructLayout( LayoutKind.Explicit )]
[StructLayout( LayoutKind.Explicit, Size = 18 )]
public struct NetworkAddress
{
[FieldOffset( 0 )]

View File

@ -2,7 +2,7 @@
namespace Steamworks.Data
{
[StructLayout( LayoutKind.Explicit, Size = 136 )]
[StructLayout( LayoutKind.Explicit, Size = 136, Pack = 8 )]
public struct NetworkIdentity
{
[FieldOffset( 0 )]

View File

@ -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
{

View File

@ -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;
}

View File

@ -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 };