diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index 4e2b3fba..26aa88af 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -66,6 +66,7 @@ public class QSBCore : ModBehaviour Application.version.Split('.').Take(3).Join(delimiter: "."); public static bool DLCInstalled => EntitlementsManager.IsDlcOwned() == EntitlementsManager.AsyncOwnershipStatus.Owned; public static bool UseKcpTransport { get; private set; } + public static ushort KcpPort { get; private set; } = 7777; public static bool ShowPlayerNames { get; private set; } public static bool ShipDamage { get; private set; } public static bool ShowExtraHUDElements { get; private set; } @@ -406,6 +407,8 @@ public class QSBCore : ModBehaviour public override void Configure(IModConfig config) { UseKcpTransport = config.GetSettingsValue("useKcpTransport") || DebugSettings.AutoStart; + var foundValue = config.GetSettingsValue("kcpPort"); + KcpPort = (ushort)Mathf.Clamp(foundValue, ushort.MinValue, ushort.MaxValue); QSBNetworkManager.UpdateTransport(); DefaultServerIP = config.GetSettingsValue("defaultServerIP"); diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs index d295de1f..fb894121 100644 --- a/QSB/QSBNetworkManager.cs +++ b/QSB/QSBNetworkManager.cs @@ -80,6 +80,7 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart _kcpTransport = gameObject.AddComponent(); // KCP uses milliseconds _kcpTransport.Timeout = QSBCore.DebugSettings.Timeout * 1000; + _kcpTransport.Port = QSBCore.KcpPort; } { @@ -161,6 +162,13 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart public static void UpdateTransport() { + if (_kcpTransport == null) + { + return; + } + + _kcpTransport.Port = QSBCore.KcpPort; + if (QSBCore.IsInMultiplayer) { return; diff --git a/QSB/default-config.json b/QSB/default-config.json index 306a1221..a9d7b059 100644 --- a/QSB/default-config.json +++ b/QSB/default-config.json @@ -20,7 +20,13 @@ "title": "Use KCP Transport", "type": "toggle", "value": false, - "tooltip": "Use alternative transport that requires port forwarding but seems to be more reliable. The port to forward is 7777 as TCP/UDP. Use this if you are having trouble connecting. ALL PLAYERS MUST HAVE THIS AS THE SAME VALUE." + "tooltip": "Use alternative transport that requires port forwarding but seems to be more reliable. Use this if you are having trouble connecting. ALL PLAYERS MUST HAVE THIS AS THE SAME VALUE." + }, + "kcpPort": { + "title": "KCP Transport Port", + "type": "number", + "value": 7777, + "tooltip": "The port to use for the KCP transport, if it is enabled. Must be port forwarded as TCP/UDP. ALL PLAYERS MUST HAVE THIS AS THE SAME VALUE." }, "defaultServerIP": { "title": "Last Entered IP/ID", diff --git a/README.md b/README.md index cf7f38a4..a7c7b5aa 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Spoilers within! ## Frequently Asked Questions ### I keep timing out when trying to connect! -Check the mod settings for "Use KCP Transport". You have to forward port 7777 as TCP/UDP, or use Hamachi. ***All players must either be using KCP, or not using KCP.*** +Check the mod settings for "Use KCP Transport". You have to forward port 7777 as TCP/UDP (or a custom port number, which can be set in the mod settings), or use Hamachi. ***All players must either be using KCP, or not using KCP.*** ### Why does SpaceWar show up in my Steam library? This is for players who own the game on Epic or Xbox. Steam networking only works if you own the game on Steam, so we have to pretend to be SpaceWar (which every Steam user owns) so everyone can play.