add custom kcp port

This commit is contained in:
_nebula 2024-12-16 01:07:21 +00:00
parent 7ec977f434
commit bb3b0dc878
4 changed files with 19 additions and 2 deletions

View File

@ -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<bool>("useKcpTransport") || DebugSettings.AutoStart;
var foundValue = config.GetSettingsValue<int>("kcpPort");
KcpPort = (ushort)Mathf.Clamp(foundValue, ushort.MinValue, ushort.MaxValue);
QSBNetworkManager.UpdateTransport();
DefaultServerIP = config.GetSettingsValue<string>("defaultServerIP");

View File

@ -80,6 +80,7 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
_kcpTransport = gameObject.AddComponent<kcp2k.KcpTransport>();
// 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;

View File

@ -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",

View File

@ -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.