From a53340ddea2c632804ee46b46ddc393cc75639db Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Fri, 4 Nov 2016 14:20:55 +0000 Subject: [PATCH] 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.