From 26e634a7f02153df43b602ae235fb7e7fe9ca2b9 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Wed, 19 Feb 2020 10:30:04 +0000 Subject: [PATCH] Restore networking interfaces --- .../Classes/ConnectionInterface.cs | 6 +--- .../Classes/SocketInterface.cs | 8 ++---- .../SteamNetworkingSockets.cs | 18 ++++++------ Facepunch.Steamworks/SteamNetworkingUtils.cs | 28 +++++++++---------- Facepunch.Steamworks/Structs/Connection.cs | 18 ++++-------- Facepunch.Steamworks/Structs/Socket.cs | 15 +++------- 6 files changed, 35 insertions(+), 58 deletions(-) diff --git a/Facepunch.Steamworks/Classes/ConnectionInterface.cs b/Facepunch.Steamworks/Classes/ConnectionInterface.cs index 76ab935..2d116aa 100644 --- a/Facepunch.Steamworks/Classes/ConnectionInterface.cs +++ b/Facepunch.Steamworks/Classes/ConnectionInterface.cs @@ -2,8 +2,6 @@ using System; using System.Runtime.InteropServices; -#if false - namespace Steamworks { public class ConnectionInterface @@ -119,6 +117,4 @@ namespace Steamworks } } -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/Facepunch.Steamworks/Classes/SocketInterface.cs b/Facepunch.Steamworks/Classes/SocketInterface.cs index e56bd82..d6998d1 100644 --- a/Facepunch.Steamworks/Classes/SocketInterface.cs +++ b/Facepunch.Steamworks/Classes/SocketInterface.cs @@ -3,8 +3,6 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using Steamworks.Data; -#if false - namespace Steamworks { public class SocketInterface @@ -69,6 +67,7 @@ namespace Steamworks int processed = 0; IntPtr messageBuffer = Marshal.AllocHGlobal( IntPtr.Size * bufferSize ); + /* try { processed = SteamNetworkingSockets.Internal.ReceiveMessagesOnListenSocket( Socket, messageBuffer, bufferSize ); @@ -82,6 +81,7 @@ namespace Steamworks { Marshal.FreeHGlobal( messageBuffer ); } + */ // // Overwhelmed our buffer, keep going @@ -111,6 +111,4 @@ namespace Steamworks } } -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/Facepunch.Steamworks/SteamNetworkingSockets.cs b/Facepunch.Steamworks/SteamNetworkingSockets.cs index dc7a919..ab6dfce 100644 --- a/Facepunch.Steamworks/SteamNetworkingSockets.cs +++ b/Facepunch.Steamworks/SteamNetworkingSockets.cs @@ -6,8 +6,6 @@ using System.Text; using System.Threading.Tasks; using Steamworks.Data; -#if false - namespace Steamworks { public class SteamNetworkingSockets : SteamClass @@ -105,7 +103,8 @@ namespace Steamworks public static T CreateNormalSocket( NetAddress address ) where T : SocketInterface, new() { var t = new T(); - t.Socket = Internal.CreateListenSocketIP( ref address ); + var options = new NetKeyValue[0]; + t.Socket = Internal.CreateListenSocketIP( ref address, options.Length, options ); SetSocketInterface( t.Socket.Id, t ); return t; } @@ -116,7 +115,8 @@ namespace Steamworks public static T ConnectNormal( NetAddress address ) where T : ConnectionInterface, new() { var t = new T(); - t.Connection = Internal.ConnectByIPAddress( ref address ); + var options = new NetKeyValue[0]; + t.Connection = Internal.ConnectByIPAddress( ref address, options.Length, options ); SetConnectionInterface( t.Connection.Id, t ); return t; } @@ -127,7 +127,8 @@ namespace Steamworks public static T CreateRelaySocket( int virtualport = 0 ) where T : SocketInterface, new() { var t = new T(); - t.Socket = Internal.CreateListenSocketP2P( virtualport ); + var options = new NetKeyValue[0]; + t.Socket = Internal.CreateListenSocketP2P( virtualport, options.Length, options ); SetSocketInterface( t.Socket.Id, t ); return t; } @@ -139,11 +140,10 @@ namespace Steamworks { var t = new T(); NetIdentity identity = serverId; - t.Connection = Internal.ConnectP2P( ref identity, virtualport ); + var options = new NetKeyValue[0]; + t.Connection = Internal.ConnectP2P( ref identity, virtualport, options.Length, options ); SetConnectionInterface( t.Connection.Id, t ); return t; } } -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/Facepunch.Steamworks/SteamNetworkingUtils.cs b/Facepunch.Steamworks/SteamNetworkingUtils.cs index c2e5418..bcb083e 100644 --- a/Facepunch.Steamworks/SteamNetworkingUtils.cs +++ b/Facepunch.Steamworks/SteamNetworkingUtils.cs @@ -5,8 +5,6 @@ using System.Text; using System.Threading.Tasks; using Steamworks.Data; -#if false - namespace Steamworks { /// @@ -63,10 +61,12 @@ namespace Steamworks if ( Internal.CheckPingDataUpToDate( 60.0f ) ) return; - while ( Internal.IsPingMeasurementInProgress() ) - { - await Task.Delay( 10 ); - } + await Task.Delay( 2000 ); + + //while ( Internal.IsPingMeasurementInProgress() ) + //{ + // await Task.Delay( 10 ); + //} } public static long LocalTimestamp => Internal.GetLocalTimestamp(); @@ -113,7 +113,7 @@ namespace Steamworks internal unsafe static bool GetConfigInt( NetConfig type, int value ) { int* ptr = &value; - return Internal.SetConfigValue( type, NetScope.Global, 0, NetConfigType.Int32, (IntPtr)ptr ); + return Internal.SetConfigValue( type, NetConfigScope.Global, 0, NetConfigType.Int32, (IntPtr)ptr ); } internal unsafe static int GetConfigInt( NetConfig type ) @@ -121,8 +121,8 @@ namespace Steamworks int value = 0; NetConfigType dtype = NetConfigType.Int32; int* ptr = &value; - ulong size = sizeof( int ); - var result = Internal.GetConfigValue( type, NetScope.Global, 0, ref dtype, (IntPtr) ptr, ref size ); + UIntPtr size = new UIntPtr( sizeof( int ) ); + var result = Internal.GetConfigValue( type, NetConfigScope.Global, 0, ref dtype, (IntPtr) ptr, ref size ); if ( result != NetConfigResult.OK ) return 0; @@ -132,7 +132,7 @@ namespace Steamworks internal unsafe static bool SetConfigFloat( NetConfig type, float value ) { float* ptr = &value; - return Internal.SetConfigValue( type, NetScope.Global, 0, NetConfigType.Float, (IntPtr)ptr ); + return Internal.SetConfigValue( type, NetConfigScope.Global, 0, NetConfigType.Float, (IntPtr)ptr ); } internal unsafe static float GetConfigFloat( NetConfig type ) @@ -140,8 +140,8 @@ namespace Steamworks float value = 0; NetConfigType dtype = NetConfigType.Float; float* ptr = &value; - ulong size = sizeof( float ); - var result = Internal.GetConfigValue( type, NetScope.Global, 0, ref dtype, (IntPtr)ptr, ref size ); + UIntPtr size = new UIntPtr( sizeof( float ) ); + var result = Internal.GetConfigValue( type, NetConfigScope.Global, 0, ref dtype, (IntPtr)ptr, ref size ); if ( result != NetConfigResult.OK ) return 0; @@ -154,7 +154,7 @@ namespace Steamworks fixed ( byte* ptr = bytes ) { - return Internal.SetConfigValue( type, NetScope.Global, 0, NetConfigType.String, (IntPtr)ptr ); + return Internal.SetConfigValue( type, NetConfigScope.Global, 0, NetConfigType.String, (IntPtr)ptr ); } } @@ -204,5 +204,3 @@ namespace Steamworks #endregion } } - -#endif \ No newline at end of file diff --git a/Facepunch.Steamworks/Structs/Connection.cs b/Facepunch.Steamworks/Structs/Connection.cs index e442cee..48c2046 100644 --- a/Facepunch.Steamworks/Structs/Connection.cs +++ b/Facepunch.Steamworks/Structs/Connection.cs @@ -1,15 +1,15 @@ using System; using System.Collections.Generic; -#if false - namespace Steamworks.Data { public struct Connection { - public uint Id { get; } + public uint Id { get; set; } public override string ToString() => Id.ToString(); + public static implicit operator Connection( uint value ) => new Connection() { Id = value }; + public static implicit operator uint( Connection value ) => value.Id; /// /// Accept an incoming connection that has been received on a listen socket. @@ -56,7 +56,8 @@ namespace Steamworks.Data public Result SendMessage( IntPtr ptr, int size, SendType sendType = SendType.Reliable ) { - return SteamNetworkingSockets.Internal.SendMessageToConnection( this, ptr, (uint) size, (int)sendType ); + long messageNumber = 0; + return SteamNetworkingSockets.Internal.SendMessageToConnection( this, ptr, (uint) size, (int)sendType, ref messageNumber ); } public unsafe Result SendMessage( byte[] data, SendType sendType = SendType.Reliable ) @@ -117,12 +118,3 @@ namespace Steamworks.Data } } -#else -namespace Steamworks.Data -{ - public struct Connection - { - public uint Id { get; } - } -} -#endif \ No newline at end of file diff --git a/Facepunch.Steamworks/Structs/Socket.cs b/Facepunch.Steamworks/Structs/Socket.cs index c0d3ab9..616250b 100644 --- a/Facepunch.Steamworks/Structs/Socket.cs +++ b/Facepunch.Steamworks/Structs/Socket.cs @@ -1,10 +1,12 @@ -#if false + namespace Steamworks.Data { public struct Socket { internal uint Id; public override string ToString() => Id.ToString(); + public static implicit operator Socket( uint value ) => new Socket() { Id = value }; + public static implicit operator uint( Socket value ) => value.Id; /// /// Destroy a listen socket. All the connections that were accepting on the listen @@ -21,13 +23,4 @@ namespace Steamworks.Data set => SteamNetworkingSockets.SetSocketInterface( Id, value ); } } -} -#else -namespace Steamworks.Data -{ - public struct Socket - { - public uint Id { get; } - } -} -#endif \ No newline at end of file +} \ No newline at end of file