diff --git a/Facepunch.Steamworks.Test/NetworkingSockets.cs b/Facepunch.Steamworks.Test/NetworkingSockets.cs index 9392ead..bcaa549 100644 --- a/Facepunch.Steamworks.Test/NetworkingSockets.cs +++ b/Facepunch.Steamworks.Test/NetworkingSockets.cs @@ -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( 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( SteamClient.SteamId, 7788 ); var client = connection.RunAsync(); @@ -62,7 +67,7 @@ namespace Steamworks var socket = SteamNetworkingSockets.CreateNormalSocket( NetAddress.AnyIp( 12445 ) ); var server = socket.RunAsync(); - await Task.Delay( 1000 ); + await Task.Delay( 5000 ); var connection = SteamNetworkingSockets.ConnectNormal( NetAddress.From( System.Net.IPAddress.Parse( "127.0.0.1" ), 12445 ) ); var client = connection.RunAsync(); @@ -286,6 +291,4 @@ namespace Steamworks } } -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/Facepunch.Steamworks.Test/NetworkingUtils.cs b/Facepunch.Steamworks.Test/NetworkingUtils.cs index bf68e82..2c84ed7 100644 --- a/Facepunch.Steamworks.Test/NetworkingUtils.cs +++ b/Facepunch.Steamworks.Test/NetworkingUtils.cs @@ -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 \ No newline at end of file +} \ No newline at end of file diff --git a/Facepunch.Steamworks/Generated/SteamEnums.cs b/Facepunch.Steamworks/Generated/SteamEnums.cs index f6614b4..359ff79 100644 --- a/Facepunch.Steamworks/Generated/SteamEnums.cs +++ b/Facepunch.Steamworks/Generated/SteamEnums.cs @@ -1950,7 +1950,7 @@ namespace Steamworks // // ESteamNetworkingAvailability // - internal enum SteamNetworkingAvailability : int + public enum SteamNetworkingAvailability : int { CannotTry = -102, Failed = -101, diff --git a/Facepunch.Steamworks/Generated/SteamStructs.cs b/Facepunch.Steamworks/Generated/SteamStructs.cs index 882c765..0660d98 100644 --- a/Facepunch.Steamworks/Generated/SteamStructs.cs +++ b/Facepunch.Steamworks/Generated/SteamStructs.cs @@ -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 { diff --git a/Facepunch.Steamworks/SteamClient.cs b/Facepunch.Steamworks/SteamClient.cs index c0b5590..0835637 100644 --- a/Facepunch.Steamworks/SteamClient.cs +++ b/Facepunch.Steamworks/SteamClient.cs @@ -45,8 +45,8 @@ namespace Steamworks AddInterface(); AddInterface(); AddInterface(); - //AddInterface(); - //AddInterface(); + AddInterface(); + AddInterface(); AddInterface(); AddInterface(); AddInterface(); diff --git a/Facepunch.Steamworks/SteamNetworkingSockets.cs b/Facepunch.Steamworks/SteamNetworkingSockets.cs index 476116c..09e3bff 100644 --- a/Facepunch.Steamworks/SteamNetworkingSockets.cs +++ b/Facepunch.Steamworks/SteamNetworkingSockets.cs @@ -69,6 +69,8 @@ namespace Steamworks } #endregion + + internal static void InstallEvents( bool server = false ) { Dispatch.Install( x => ConnectionStatusChanged( x ), server ); diff --git a/Facepunch.Steamworks/SteamNetworkingUtils.cs b/Facepunch.Steamworks/SteamNetworkingUtils.cs index c13b21e..7dc263e 100644 --- a/Facepunch.Steamworks/SteamNetworkingUtils.cs +++ b/Facepunch.Steamworks/SteamNetworkingUtils.cs @@ -20,6 +20,43 @@ namespace Steamworks Internal = new ISteamNetworkingUtils( server ); } + static void InstallCallbacks() + { + Dispatch.Install( x => + { + Status = x.Avail; + } ); + } + + public static SteamNetworkingAvailability Status { get; private set; } + + /// + /// 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. + /// + public static void InitRelayNetworkAccess() + { + Internal.InitRelayNetworkAccess(); + } + /// /// Return location info for the current host. /// @@ -58,15 +95,15 @@ namespace Steamworks /// 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(); diff --git a/Facepunch.Steamworks/SteamServer.cs b/Facepunch.Steamworks/SteamServer.cs index ca78d92..4c1fd68 100644 --- a/Facepunch.Steamworks/SteamServer.cs +++ b/Facepunch.Steamworks/SteamServer.cs @@ -94,6 +94,8 @@ namespace Steamworks Console.WriteLine( $"Dispatch.ServerPipe = {Dispatch.ServerPipe.Value}" ); AddInterface(); + AddInterface(); + AddInterface(); // // Initial settings diff --git a/Facepunch.Steamworks/Structs/PingLocation.cs b/Facepunch.Steamworks/Structs/PingLocation.cs index e2085a8..9eb0a95 100644 --- a/Facepunch.Steamworks/Structs/PingLocation.cs +++ b/Facepunch.Steamworks/Structs/PingLocation.cs @@ -1,7 +1,5 @@ using System.Runtime.InteropServices; -#if false - namespace Steamworks.Data { /// @@ -66,6 +64,4 @@ namespace Steamworks.Data return SteamNetworkingUtils.Internal.EstimatePingTimeBetweenTwoLocations( ref this, ref target ); } } -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/Facepunch.Steamworks/Structs/Socket.cs b/Facepunch.Steamworks/Structs/Socket.cs index 616250b..864223e 100644 --- a/Facepunch.Steamworks/Structs/Socket.cs +++ b/Facepunch.Steamworks/Structs/Socket.cs @@ -1,6 +1,9 @@  +using System.Runtime.InteropServices; + namespace Steamworks.Data { + [StructLayout( LayoutKind.Sequential )] public struct Socket { internal uint Id; diff --git a/Generator/Cleanup.cs b/Generator/Cleanup.cs index aad47b2..1f11137 100644 --- a/Generator/Cleanup.cs +++ b/Generator/Cleanup.cs @@ -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"; }