Restore network tests

This commit is contained in:
Garry Newman 2020-02-19 15:29:18 +00:00
parent 9bac5a32c2
commit 0d98fd9de9
11 changed files with 69 additions and 35 deletions

View File

@ -7,12 +7,11 @@ using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Steamworks.Data;
#if false
namespace Steamworks
{
[TestClass]
[DeploymentItem( "steam_api64.dll" )]
[DeploymentItem( "steam_api.dll" )]
public class NetworkingSocketsTest
{
@ -45,11 +44,17 @@ namespace Steamworks
[TestMethod]
public async Task RelayEndtoEnd()
{
SteamNetworkingUtils.InitRelayNetworkAccess();
Console.WriteLine( $"----- Creating Socket Relay Socket.." );
var socket = SteamNetworkingSockets.CreateRelaySocket<TestSocketInterface>( 7788 );
var server = socket.RunAsync();
await Task.Delay( 1000 );
Console.WriteLine( $"----- Created Relay Socket: {(uint)socket.Socket}" );
await Task.Delay( 5000 );
Console.WriteLine( $"----- Connecting To Socket via SteamId ({SteamClient.SteamId})" );
var connection = SteamNetworkingSockets.ConnectRelay<TestConnectionInterface>( SteamClient.SteamId, 7788 );
var client = connection.RunAsync();
@ -62,7 +67,7 @@ namespace Steamworks
var socket = SteamNetworkingSockets.CreateNormalSocket<TestSocketInterface>( NetAddress.AnyIp( 12445 ) );
var server = socket.RunAsync();
await Task.Delay( 1000 );
await Task.Delay( 5000 );
var connection = SteamNetworkingSockets.ConnectNormal<TestConnectionInterface>( NetAddress.From( System.Net.IPAddress.Parse( "127.0.0.1" ), 12445 ) );
var client = connection.RunAsync();
@ -286,6 +291,4 @@ namespace Steamworks
}
}
}
#endif
}

View File

@ -5,15 +5,14 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
#if false
namespace Steamworks
{
[TestClass]
[DeploymentItem( "steam_api64.dll" )]
[DeploymentItem( "steam_api.dll" )]
public class NetworkUtilsTest
{
static string GarrysLocation = "lhr=19+1,ams=25+2/25+1,par=29+2,fra=31+3/30+1,lux=33+3,vie=44+4/41+1,waw=47+4/45+1,sto2=48+4/46+2,sto=50+5/46+2,iad=107+10/91+1,sgp=186+18,gru=252+25/234+1";
static string GarrysLocation = "lhr=4+0,ams=13+1/10+0,par=17+1/12+0,lux=17+1,fra=18+1/18+0,sto=25+2,sto2=26+2,mad=27+2,vie=31+3/30+0,iad=90+9/75+0,sgp=173+17/174+17,gru=200+20/219+0";
[TestMethod]
public async Task LocalPingLocation()
@ -61,6 +60,4 @@ namespace Steamworks
}
}
}
#endif
}

View File

@ -1950,7 +1950,7 @@ namespace Steamworks
//
// ESteamNetworkingAvailability
//
internal enum SteamNetworkingAvailability : int
public enum SteamNetworkingAvailability : int
{
CannotTry = -102,
Failed = -101,

View File

@ -178,14 +178,6 @@ namespace Steamworks.Data
}
[StructLayout( LayoutKind.Sequential, Pack = Platform.StructPlatformPackSize )]
public struct PingLocation
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)] // m_data
internal byte[] Data; // m_data uint8 [512]
}
[StructLayout( LayoutKind.Sequential, Pack = Platform.StructPlatformPackSize )]
internal struct SteamDatagramHostedAddress
{

View File

@ -45,8 +45,8 @@ namespace Steamworks
AddInterface<SteamMatchmakingServers>();
AddInterface<SteamMusic>();
AddInterface<SteamNetworking>();
//AddInterface<SteamNetworkingSockets>();
//AddInterface<SteamNetworkingUtils>();
AddInterface<SteamNetworkingSockets>();
AddInterface<SteamNetworkingUtils>();
AddInterface<SteamParental>();
AddInterface<SteamParties>();
AddInterface<SteamRemoteStorage>();

View File

@ -69,6 +69,8 @@ namespace Steamworks
}
#endregion
internal static void InstallEvents( bool server = false )
{
Dispatch.Install<SteamNetConnectionStatusChangedCallback_t>( x => ConnectionStatusChanged( x ), server );

View File

@ -20,6 +20,43 @@ namespace Steamworks
Internal = new ISteamNetworkingUtils( server );
}
static void InstallCallbacks()
{
Dispatch.Install<SteamRelayNetworkStatus_t>( x =>
{
Status = x.Avail;
} );
}
public static SteamNetworkingAvailability Status { get; private set; }
/// <summary>
/// If you know that you are going to be using the relay network (for example,
/// because you anticipate making P2P connections), call this to initialize the
/// relay network. If you do not call this, the initialization will
/// be delayed until the first time you use a feature that requires access
/// to the relay network, which will delay that first access.
///
/// You can also call this to force a retry if the previous attempt has failed.
/// Performing any action that requires access to the relay network will also
/// trigger a retry, and so calling this function is never strictly necessary,
/// but it can be useful to call it a program launch time, if access to the
/// relay network is anticipated.
///
/// Use GetRelayNetworkStatus or listen for SteamRelayNetworkStatus_t
/// callbacks to know when initialization has completed.
/// Typically initialization completes in a few seconds.
///
/// Note: dedicated servers hosted in known data centers do *not* need
/// to call this, since they do not make routing decisions. However, if
/// the dedicated server will be using P2P functionality, it will act as
/// a "client" and this should be called.
/// </summary>
public static void InitRelayNetworkAccess()
{
Internal.InitRelayNetworkAccess();
}
/// <summary>
/// Return location info for the current host.
///
@ -58,15 +95,15 @@ namespace Steamworks
/// </summary>
public static async Task WaitForPingDataAsync( float maxAgeInSeconds = 60 * 5 )
{
if ( Internal.CheckPingDataUpToDate( 60.0f ) )
if ( Internal.CheckPingDataUpToDate( 120.0f ) )
return;
await Task.Delay( 2000 );
SteamRelayNetworkStatus_t status = default;
//while ( Internal.IsPingMeasurementInProgress() )
//{
// await Task.Delay( 10 );
//}
while ( Internal.GetRelayNetworkStatus( ref status ) != SteamNetworkingAvailability.Current )
{
await Task.Delay( 10 );
}
}
public static long LocalTimestamp => Internal.GetLocalTimestamp();

View File

@ -94,6 +94,8 @@ namespace Steamworks
Console.WriteLine( $"Dispatch.ServerPipe = {Dispatch.ServerPipe.Value}" );
AddInterface<SteamServer>();
AddInterface<SteamNetworkingUtils>();
AddInterface<SteamNetworkingSockets>();
//
// Initial settings

View File

@ -1,7 +1,5 @@
using System.Runtime.InteropServices;
#if false
namespace Steamworks.Data
{
/// <summary>
@ -66,6 +64,4 @@ namespace Steamworks.Data
return SteamNetworkingUtils.Internal.EstimatePingTimeBetweenTwoLocations( ref this, ref target );
}
}
}
#endif
}

View File

@ -1,6 +1,9 @@

using System.Runtime.InteropServices;
namespace Steamworks.Data
{
[StructLayout( LayoutKind.Sequential )]
public struct Socket
{
internal uint Id;

View File

@ -85,6 +85,7 @@ public static class Cleanup
if ( type == "SteamNetworkingErrMsg" ) return false;
if ( type == "NetKeyValue" ) return false;
if ( type == "SteamIPAddress" ) return false;
if ( type == "PingLocation" ) return false;
return true;
}
@ -117,6 +118,7 @@ public static class Cleanup
if ( name == "UserHasLicenseForAppResult" ) return "public";
if ( name == "PingLocation" ) return "public";
if ( name == "ConnectionState" ) return "public";
if ( name == "SteamNetworkingAvailability" ) return "public";
return "internal";
}