mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-02-06 02:30:36 +03:00
Restore network tests
This commit is contained in:
parent
9bac5a32c2
commit
0d98fd9de9
@ -7,12 +7,11 @@ using System.Threading.Tasks;
|
|||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using Steamworks.Data;
|
using Steamworks.Data;
|
||||||
|
|
||||||
#if false
|
|
||||||
|
|
||||||
namespace Steamworks
|
namespace Steamworks
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
[DeploymentItem( "steam_api64.dll" )]
|
[DeploymentItem( "steam_api64.dll" )]
|
||||||
|
[DeploymentItem( "steam_api.dll" )]
|
||||||
public class NetworkingSocketsTest
|
public class NetworkingSocketsTest
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -45,11 +44,17 @@ namespace Steamworks
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public async Task RelayEndtoEnd()
|
public async Task RelayEndtoEnd()
|
||||||
{
|
{
|
||||||
|
SteamNetworkingUtils.InitRelayNetworkAccess();
|
||||||
|
|
||||||
|
Console.WriteLine( $"----- Creating Socket Relay Socket.." );
|
||||||
var socket = SteamNetworkingSockets.CreateRelaySocket<TestSocketInterface>( 7788 );
|
var socket = SteamNetworkingSockets.CreateRelaySocket<TestSocketInterface>( 7788 );
|
||||||
var server = socket.RunAsync();
|
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 connection = SteamNetworkingSockets.ConnectRelay<TestConnectionInterface>( SteamClient.SteamId, 7788 );
|
||||||
var client = connection.RunAsync();
|
var client = connection.RunAsync();
|
||||||
|
|
||||||
@ -62,7 +67,7 @@ namespace Steamworks
|
|||||||
var socket = SteamNetworkingSockets.CreateNormalSocket<TestSocketInterface>( NetAddress.AnyIp( 12445 ) );
|
var socket = SteamNetworkingSockets.CreateNormalSocket<TestSocketInterface>( NetAddress.AnyIp( 12445 ) );
|
||||||
var server = socket.RunAsync();
|
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 connection = SteamNetworkingSockets.ConnectNormal<TestConnectionInterface>( NetAddress.From( System.Net.IPAddress.Parse( "127.0.0.1" ), 12445 ) );
|
||||||
var client = connection.RunAsync();
|
var client = connection.RunAsync();
|
||||||
@ -286,6 +291,4 @@ namespace Steamworks
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
@ -5,15 +5,14 @@ using System.Threading;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
#if false
|
|
||||||
|
|
||||||
namespace Steamworks
|
namespace Steamworks
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
[DeploymentItem( "steam_api64.dll" )]
|
[DeploymentItem( "steam_api64.dll" )]
|
||||||
|
[DeploymentItem( "steam_api.dll" )]
|
||||||
public class NetworkUtilsTest
|
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]
|
[TestMethod]
|
||||||
public async Task LocalPingLocation()
|
public async Task LocalPingLocation()
|
||||||
@ -61,6 +60,4 @@ namespace Steamworks
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
@ -1950,7 +1950,7 @@ namespace Steamworks
|
|||||||
//
|
//
|
||||||
// ESteamNetworkingAvailability
|
// ESteamNetworkingAvailability
|
||||||
//
|
//
|
||||||
internal enum SteamNetworkingAvailability : int
|
public enum SteamNetworkingAvailability : int
|
||||||
{
|
{
|
||||||
CannotTry = -102,
|
CannotTry = -102,
|
||||||
Failed = -101,
|
Failed = -101,
|
||||||
|
@ -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 )]
|
[StructLayout( LayoutKind.Sequential, Pack = Platform.StructPlatformPackSize )]
|
||||||
internal struct SteamDatagramHostedAddress
|
internal struct SteamDatagramHostedAddress
|
||||||
{
|
{
|
||||||
|
@ -45,8 +45,8 @@ namespace Steamworks
|
|||||||
AddInterface<SteamMatchmakingServers>();
|
AddInterface<SteamMatchmakingServers>();
|
||||||
AddInterface<SteamMusic>();
|
AddInterface<SteamMusic>();
|
||||||
AddInterface<SteamNetworking>();
|
AddInterface<SteamNetworking>();
|
||||||
//AddInterface<SteamNetworkingSockets>();
|
AddInterface<SteamNetworkingSockets>();
|
||||||
//AddInterface<SteamNetworkingUtils>();
|
AddInterface<SteamNetworkingUtils>();
|
||||||
AddInterface<SteamParental>();
|
AddInterface<SteamParental>();
|
||||||
AddInterface<SteamParties>();
|
AddInterface<SteamParties>();
|
||||||
AddInterface<SteamRemoteStorage>();
|
AddInterface<SteamRemoteStorage>();
|
||||||
|
@ -69,6 +69,8 @@ namespace Steamworks
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
internal static void InstallEvents( bool server = false )
|
internal static void InstallEvents( bool server = false )
|
||||||
{
|
{
|
||||||
Dispatch.Install<SteamNetConnectionStatusChangedCallback_t>( x => ConnectionStatusChanged( x ), server );
|
Dispatch.Install<SteamNetConnectionStatusChangedCallback_t>( x => ConnectionStatusChanged( x ), server );
|
||||||
|
@ -20,6 +20,43 @@ namespace Steamworks
|
|||||||
Internal = new ISteamNetworkingUtils( server );
|
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>
|
/// <summary>
|
||||||
/// Return location info for the current host.
|
/// Return location info for the current host.
|
||||||
///
|
///
|
||||||
@ -58,15 +95,15 @@ namespace Steamworks
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static async Task WaitForPingDataAsync( float maxAgeInSeconds = 60 * 5 )
|
public static async Task WaitForPingDataAsync( float maxAgeInSeconds = 60 * 5 )
|
||||||
{
|
{
|
||||||
if ( Internal.CheckPingDataUpToDate( 60.0f ) )
|
if ( Internal.CheckPingDataUpToDate( 120.0f ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
await Task.Delay( 2000 );
|
SteamRelayNetworkStatus_t status = default;
|
||||||
|
|
||||||
//while ( Internal.IsPingMeasurementInProgress() )
|
while ( Internal.GetRelayNetworkStatus( ref status ) != SteamNetworkingAvailability.Current )
|
||||||
//{
|
{
|
||||||
// await Task.Delay( 10 );
|
await Task.Delay( 10 );
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long LocalTimestamp => Internal.GetLocalTimestamp();
|
public static long LocalTimestamp => Internal.GetLocalTimestamp();
|
||||||
|
@ -94,6 +94,8 @@ namespace Steamworks
|
|||||||
Console.WriteLine( $"Dispatch.ServerPipe = {Dispatch.ServerPipe.Value}" );
|
Console.WriteLine( $"Dispatch.ServerPipe = {Dispatch.ServerPipe.Value}" );
|
||||||
|
|
||||||
AddInterface<SteamServer>();
|
AddInterface<SteamServer>();
|
||||||
|
AddInterface<SteamNetworkingUtils>();
|
||||||
|
AddInterface<SteamNetworkingSockets>();
|
||||||
|
|
||||||
//
|
//
|
||||||
// Initial settings
|
// Initial settings
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
#if false
|
|
||||||
|
|
||||||
namespace Steamworks.Data
|
namespace Steamworks.Data
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -66,6 +64,4 @@ namespace Steamworks.Data
|
|||||||
return SteamNetworkingUtils.Internal.EstimatePingTimeBetweenTwoLocations( ref this, ref target );
|
return SteamNetworkingUtils.Internal.EstimatePingTimeBetweenTwoLocations( ref this, ref target );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
@ -1,6 +1,9 @@
|
|||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace Steamworks.Data
|
namespace Steamworks.Data
|
||||||
{
|
{
|
||||||
|
[StructLayout( LayoutKind.Sequential )]
|
||||||
public struct Socket
|
public struct Socket
|
||||||
{
|
{
|
||||||
internal uint Id;
|
internal uint Id;
|
||||||
|
@ -85,6 +85,7 @@ public static class Cleanup
|
|||||||
if ( type == "SteamNetworkingErrMsg" ) return false;
|
if ( type == "SteamNetworkingErrMsg" ) return false;
|
||||||
if ( type == "NetKeyValue" ) return false;
|
if ( type == "NetKeyValue" ) return false;
|
||||||
if ( type == "SteamIPAddress" ) return false;
|
if ( type == "SteamIPAddress" ) return false;
|
||||||
|
if ( type == "PingLocation" ) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -117,6 +118,7 @@ public static class Cleanup
|
|||||||
if ( name == "UserHasLicenseForAppResult" ) return "public";
|
if ( name == "UserHasLicenseForAppResult" ) return "public";
|
||||||
if ( name == "PingLocation" ) return "public";
|
if ( name == "PingLocation" ) return "public";
|
||||||
if ( name == "ConnectionState" ) return "public";
|
if ( name == "ConnectionState" ) return "public";
|
||||||
|
if ( name == "SteamNetworkingAvailability" ) return "public";
|
||||||
|
|
||||||
return "internal";
|
return "internal";
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user