Restore networking interfaces

This commit is contained in:
Garry Newman 2020-02-19 10:30:04 +00:00
parent 798bfa991e
commit 26e634a7f0
6 changed files with 35 additions and 58 deletions

View File

@ -2,8 +2,6 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
#if false
namespace Steamworks namespace Steamworks
{ {
public class ConnectionInterface public class ConnectionInterface
@ -120,5 +118,3 @@ namespace Steamworks
} }
} }
} }
#endif

View File

@ -3,8 +3,6 @@ using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Steamworks.Data; using Steamworks.Data;
#if false
namespace Steamworks namespace Steamworks
{ {
public class SocketInterface public class SocketInterface
@ -69,6 +67,7 @@ namespace Steamworks
int processed = 0; int processed = 0;
IntPtr messageBuffer = Marshal.AllocHGlobal( IntPtr.Size * bufferSize ); IntPtr messageBuffer = Marshal.AllocHGlobal( IntPtr.Size * bufferSize );
/*
try try
{ {
processed = SteamNetworkingSockets.Internal.ReceiveMessagesOnListenSocket( Socket, messageBuffer, bufferSize ); processed = SteamNetworkingSockets.Internal.ReceiveMessagesOnListenSocket( Socket, messageBuffer, bufferSize );
@ -82,6 +81,7 @@ namespace Steamworks
{ {
Marshal.FreeHGlobal( messageBuffer ); Marshal.FreeHGlobal( messageBuffer );
} }
*/
// //
// Overwhelmed our buffer, keep going // Overwhelmed our buffer, keep going
@ -112,5 +112,3 @@ namespace Steamworks
} }
} }
} }
#endif

View File

@ -6,8 +6,6 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Steamworks.Data; using Steamworks.Data;
#if false
namespace Steamworks namespace Steamworks
{ {
public class SteamNetworkingSockets : SteamClass public class SteamNetworkingSockets : SteamClass
@ -105,7 +103,8 @@ namespace Steamworks
public static T CreateNormalSocket<T>( NetAddress address ) where T : SocketInterface, new() public static T CreateNormalSocket<T>( NetAddress address ) where T : SocketInterface, new()
{ {
var t = new T(); 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 ); SetSocketInterface( t.Socket.Id, t );
return t; return t;
} }
@ -116,7 +115,8 @@ namespace Steamworks
public static T ConnectNormal<T>( NetAddress address ) where T : ConnectionInterface, new() public static T ConnectNormal<T>( NetAddress address ) where T : ConnectionInterface, new()
{ {
var t = new T(); 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 ); SetConnectionInterface( t.Connection.Id, t );
return t; return t;
} }
@ -127,7 +127,8 @@ namespace Steamworks
public static T CreateRelaySocket<T>( int virtualport = 0 ) where T : SocketInterface, new() public static T CreateRelaySocket<T>( int virtualport = 0 ) where T : SocketInterface, new()
{ {
var t = new T(); 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 ); SetSocketInterface( t.Socket.Id, t );
return t; return t;
} }
@ -139,11 +140,10 @@ namespace Steamworks
{ {
var t = new T(); var t = new T();
NetIdentity identity = serverId; 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 ); SetConnectionInterface( t.Connection.Id, t );
return t; return t;
} }
} }
} }
#endif

View File

@ -5,8 +5,6 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Steamworks.Data; using Steamworks.Data;
#if false
namespace Steamworks namespace Steamworks
{ {
/// <summary> /// <summary>
@ -63,10 +61,12 @@ namespace Steamworks
if ( Internal.CheckPingDataUpToDate( 60.0f ) ) if ( Internal.CheckPingDataUpToDate( 60.0f ) )
return; return;
while ( Internal.IsPingMeasurementInProgress() ) await Task.Delay( 2000 );
{
await Task.Delay( 10 ); //while ( Internal.IsPingMeasurementInProgress() )
} //{
// await Task.Delay( 10 );
//}
} }
public static long LocalTimestamp => Internal.GetLocalTimestamp(); public static long LocalTimestamp => Internal.GetLocalTimestamp();
@ -113,7 +113,7 @@ namespace Steamworks
internal unsafe static bool GetConfigInt( NetConfig type, int value ) internal unsafe static bool GetConfigInt( NetConfig type, int value )
{ {
int* ptr = &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 ) internal unsafe static int GetConfigInt( NetConfig type )
@ -121,8 +121,8 @@ namespace Steamworks
int value = 0; int value = 0;
NetConfigType dtype = NetConfigType.Int32; NetConfigType dtype = NetConfigType.Int32;
int* ptr = &value; int* ptr = &value;
ulong size = sizeof( int ); UIntPtr size = new UIntPtr( sizeof( int ) );
var result = Internal.GetConfigValue( type, NetScope.Global, 0, ref dtype, (IntPtr) ptr, ref size ); var result = Internal.GetConfigValue( type, NetConfigScope.Global, 0, ref dtype, (IntPtr) ptr, ref size );
if ( result != NetConfigResult.OK ) if ( result != NetConfigResult.OK )
return 0; return 0;
@ -132,7 +132,7 @@ namespace Steamworks
internal unsafe static bool SetConfigFloat( NetConfig type, float value ) internal unsafe static bool SetConfigFloat( NetConfig type, float value )
{ {
float* ptr = &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 ) internal unsafe static float GetConfigFloat( NetConfig type )
@ -140,8 +140,8 @@ namespace Steamworks
float value = 0; float value = 0;
NetConfigType dtype = NetConfigType.Float; NetConfigType dtype = NetConfigType.Float;
float* ptr = &value; float* ptr = &value;
ulong size = sizeof( float ); UIntPtr size = new UIntPtr( sizeof( float ) );
var result = Internal.GetConfigValue( type, NetScope.Global, 0, ref dtype, (IntPtr)ptr, ref size ); var result = Internal.GetConfigValue( type, NetConfigScope.Global, 0, ref dtype, (IntPtr)ptr, ref size );
if ( result != NetConfigResult.OK ) if ( result != NetConfigResult.OK )
return 0; return 0;
@ -154,7 +154,7 @@ namespace Steamworks
fixed ( byte* ptr = bytes ) 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 #endregion
} }
} }
#endif

View File

@ -1,15 +1,15 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
#if false
namespace Steamworks.Data namespace Steamworks.Data
{ {
public struct Connection public struct Connection
{ {
public uint Id { get; } public uint Id { get; set; }
public override string ToString() => Id.ToString(); 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;
/// <summary> /// <summary>
/// Accept an incoming connection that has been received on a listen socket. /// 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 ) 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 ) 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

View File

@ -1,10 +1,12 @@
#if false 
namespace Steamworks.Data namespace Steamworks.Data
{ {
public struct Socket public struct Socket
{ {
internal uint Id; internal uint Id;
public override string ToString() => Id.ToString(); 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;
/// <summary> /// <summary>
/// Destroy a listen socket. All the connections that were accepting on the listen /// Destroy a listen socket. All the connections that were accepting on the listen
@ -22,12 +24,3 @@ namespace Steamworks.Data
} }
} }
} }
#else
namespace Steamworks.Data
{
public struct Socket
{
public uint Id { get; }
}
}
#endif