mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-27 07:05:50 +03:00
ConnectionInfo
This commit is contained in:
parent
ce3525bf1d
commit
6be5826f31
@ -54,8 +54,7 @@ public async Task ConnectToRelayServer()
|
|||||||
connection.UserData = 69;
|
connection.UserData = 69;
|
||||||
|
|
||||||
// Give it a second for something to happen
|
// Give it a second for something to happen
|
||||||
await Task.Delay( 5000 );
|
await Task.Delay( 1000 );
|
||||||
|
|
||||||
|
|
||||||
connection.Close();
|
connection.Close();
|
||||||
|
|
||||||
|
@ -216,11 +216,11 @@ internal int ReceiveMessagesOnListenSocket( Socket hSocket, [In,Out] ref SteamNe
|
|||||||
#region FunctionMeta
|
#region FunctionMeta
|
||||||
[UnmanagedFunctionPointer( CallingConvention.ThisCall )]
|
[UnmanagedFunctionPointer( CallingConvention.ThisCall )]
|
||||||
[return: MarshalAs( UnmanagedType.I1 )]
|
[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;
|
private FGetConnectionInfo _GetConnectionInfo;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
internal bool GetConnectionInfo( NetConnection hConn, ref SteamNetConnectionInfo_t pInfo )
|
internal bool GetConnectionInfo( NetConnection hConn, ref ConnectionInfo pInfo )
|
||||||
{
|
{
|
||||||
return _GetConnectionInfo( Self, hConn, ref pInfo );
|
return _GetConnectionInfo( Self, hConn, ref pInfo );
|
||||||
}
|
}
|
||||||
|
@ -12136,7 +12136,7 @@ public struct Pack8
|
|||||||
internal struct SteamNetConnectionStatusChangedCallback_t
|
internal struct SteamNetConnectionStatusChangedCallback_t
|
||||||
{
|
{
|
||||||
internal NetConnection Conn; // m_hConn HSteamNetConnection
|
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
|
internal SteamNetworkingConnectionState OldState; // m_eOldState ESteamNetworkingConnectionState
|
||||||
|
|
||||||
#region SteamCallback
|
#region SteamCallback
|
||||||
@ -12191,7 +12191,7 @@ public static void Install( Action<SteamNetConnectionStatusChangedCallback_t> ac
|
|||||||
public struct Pack8
|
public struct Pack8
|
||||||
{
|
{
|
||||||
internal NetConnection Conn; // m_hConn HSteamNetConnection
|
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
|
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, };
|
public static implicit operator SteamNetConnectionStatusChangedCallback_t ( SteamNetConnectionStatusChangedCallback_t.Pack8 d ) => new SteamNetConnectionStatusChangedCallback_t{ Conn = d.Conn,Nfo = d.Nfo,OldState = d.OldState, };
|
||||||
|
@ -37,13 +37,44 @@ internal static void InstallEvents()
|
|||||||
|
|
||||||
private static void OnConnectionStatusChanged( SteamNetConnectionStatusChangedCallback_t data )
|
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: {data.Conn.ToString()}" );
|
||||||
Console.WriteLine( $"data.Conn.UserData: {data.Conn.UserData}" );
|
Console.WriteLine( $"data.Conn.UserData: {data.Conn.UserData}" );
|
||||||
Console.WriteLine( $"data.Conn.ConnectionName: {data.Conn.ConnectionName}" );
|
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>
|
/// <summary>
|
||||||
/// Creates a "server" socket that listens for clients to connect to by calling
|
/// Creates a "server" socket that listens for clients to connect to by calling
|
||||||
/// Connect, over ordinary UDP (IPv4 or IPv6)
|
/// Connect, over ordinary UDP (IPv4 or IPv6)
|
||||||
|
22
Facepunch.Steamworks/Structs/ConnectionInfo.cs
Normal file
22
Facepunch.Steamworks/Structs/ConnectionInfo.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -5,17 +5,7 @@ namespace Steamworks.Data
|
|||||||
{
|
{
|
||||||
public struct NetConnection
|
public struct NetConnection
|
||||||
{
|
{
|
||||||
uint Id;
|
internal uint Id;
|
||||||
|
|
||||||
public static implicit operator NetConnection( uint value )
|
|
||||||
{
|
|
||||||
return new NetConnection { Id = value };
|
|
||||||
}
|
|
||||||
|
|
||||||
public static implicit operator uint( NetConnection value )
|
|
||||||
{
|
|
||||||
return value.Id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString() => Id.ToString();
|
public override string ToString() => Id.ToString();
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Steamworks.Data
|
namespace Steamworks.Data
|
||||||
{
|
{
|
||||||
[StructLayout( LayoutKind.Explicit )]
|
[StructLayout( LayoutKind.Explicit, Size = 18 )]
|
||||||
public struct NetworkAddress
|
public struct NetworkAddress
|
||||||
{
|
{
|
||||||
[FieldOffset( 0 )]
|
[FieldOffset( 0 )]
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Steamworks.Data
|
namespace Steamworks.Data
|
||||||
{
|
{
|
||||||
[StructLayout( LayoutKind.Explicit, Size = 136 )]
|
[StructLayout( LayoutKind.Explicit, Size = 136, Pack = 8 )]
|
||||||
public struct NetworkIdentity
|
public struct NetworkIdentity
|
||||||
{
|
{
|
||||||
[FieldOffset( 0 )]
|
[FieldOffset( 0 )]
|
||||||
|
@ -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 )]
|
[StructLayout( LayoutKind.Sequential )]
|
||||||
public struct SteamNetworkingQuickConnectionStatus
|
public struct SteamNetworkingQuickConnectionStatus
|
||||||
{
|
{
|
||||||
|
@ -34,6 +34,7 @@ public static string ConvertType( string type )
|
|||||||
type = type.Replace( "HSteamListenSocket", "Socket" );
|
type = type.Replace( "HSteamListenSocket", "Socket" );
|
||||||
type = type.Replace( "SteamNetworkingIPAddr", "NetworkAddress" );
|
type = type.Replace( "SteamNetworkingIPAddr", "NetworkAddress" );
|
||||||
type = type.Replace( "SteamNetworkingIdentity", "NetworkIdentity" );
|
type = type.Replace( "SteamNetworkingIdentity", "NetworkIdentity" );
|
||||||
|
type = type.Replace( "SteamNetConnectionInfo_t", "ConnectionInfo" );
|
||||||
|
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
@ -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 == "InventoryItemId" ) return new StructType { NativeType = type, VarName = varname, StructName = basicType };
|
||||||
if ( basicType == "InventoryDefId" ) 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 == "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 == "NetworkIdentity" ) return new StructType { NativeType = type, VarName = varname, StructName = basicType };
|
||||||
if ( basicType == "NetworkAddress" ) 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 };
|
if ( basicType.StartsWith( "E" ) && char.IsUpper( basicType[1] ) ) return new EnumType { NativeType = type.Substring( 1 ), VarName = varname };
|
||||||
|
|
||||||
return new BaseType { NativeType = type, VarName = varname };
|
return new BaseType { NativeType = type, VarName = varname };
|
||||||
|
Loading…
Reference in New Issue
Block a user