From aa28a78d8c1862244df7200a0a552f2d566b3f90 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Fri, 4 Nov 2016 14:20:13 +0000 Subject: [PATCH 1/2] Use GetAvailableVoice --- Facepunch.Steamworks/Client/Voice.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Facepunch.Steamworks/Client/Voice.cs b/Facepunch.Steamworks/Client/Voice.cs index 639b430..d7fbbb7 100644 --- a/Facepunch.Steamworks/Client/Voice.cs +++ b/Facepunch.Steamworks/Client/Voice.cs @@ -102,7 +102,15 @@ namespace Facepunch.Steamworks uint bufferRegularLastWrite = 0; uint bufferCompressedLastWrite = 0; - var result = client.native.user.GetVoice( OnCompressedData != null, ReadCompressedBuffer, ReadBufferSize, out bufferCompressedLastWrite, + var result = client.native.user.GetAvailableVoice( out bufferCompressedLastWrite, out bufferRegularLastWrite, DesiredSampleRate == 0 ? OptimalSampleRate : DesiredSampleRate ); + + if ( result == SteamNative.VoiceResult.NotRecording || result == SteamNative.VoiceResult.NotInitialized ) + { + IsRecording = false; + return; + } + + result = client.native.user.GetVoice( OnCompressedData != null, ReadCompressedBuffer, ReadBufferSize, out bufferCompressedLastWrite, OnUncompressedData != null, (IntPtr) ReadUncompressedBuffer, ReadBufferSize, out bufferRegularLastWrite, DesiredSampleRate == 0 ? OptimalSampleRate : DesiredSampleRate ); From a53340ddea2c632804ee46b46ddc393cc75639db Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Fri, 4 Nov 2016 14:20:55 +0000 Subject: [PATCH 2/2] randomize steam port by default --- Facepunch.Steamworks/Server.cs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Facepunch.Steamworks/Server.cs b/Facepunch.Steamworks/Server.cs index 7d2a5fe..c3d3be4 100644 --- a/Facepunch.Steamworks/Server.cs +++ b/Facepunch.Steamworks/Server.cs @@ -34,18 +34,28 @@ namespace Facepunch.Steamworks /// /// You game's AppId /// The IP Address to bind to. Can be 0 to mean "any". + /// Port to talk to steam on, can be anything as long as it's not used.". /// The port you game listens to for connections. /// The port Steam should use for server queries. /// True if you want to use VAC /// A string defining version, ie "1001" - public Server( uint appId, uint IpAddress, ushort GamePort, ushort QueryPort, bool Secure, string VersionString ) + public Server( uint appId, uint IpAddress, ushort SteamPort, ushort GamePort, ushort QueryPort, bool Secure, string VersionString ) { native = new Interop.NativeInterface(); + // + // If we don't have a SteamPort defined, choose one at 'random' + // + if ( SteamPort == 0 ) + { + SteamPort = (ushort) new Random().Next( 10000, 60000 ); + } + + // // Get other interfaces // - if ( !native.InitServer( this, IpAddress, 0, GamePort, QueryPort, Secure ? 3 : 2, VersionString ) ) + if ( !native.InitServer( this, IpAddress, SteamPort, GamePort, QueryPort, Secure ? 3 : 2, VersionString ) ) { native.Dispose(); native = null; @@ -83,6 +93,20 @@ namespace Facepunch.Steamworks Update(); } + /// + /// Initialize a Steam Server instance + /// + /// You game's AppId + /// The IP Address to bind to. Can be 0 to mean "any". + /// The port you game listens to for connections. + /// The port Steam should use for server queries. + /// True if you want to use VAC + /// A string defining version, ie "1001" + public Server( uint appId, uint IpAddress, ushort GamePort, ushort QueryPort, bool Secure, string VersionString ) : this( appId, IpAddress, 0, GamePort, QueryPort, Secure, VersionString ) + { + + } + /// /// Initialize a server - query port will use the same as GamePort (MASTERSERVERUPDATERPORT_USEGAMESOCKETSHARE) /// This means you'll need to detect and manually process and reply to server queries.