Skip to content

Commit

Permalink
Added NatPunchPort config
Browse files Browse the repository at this point in the history
  • Loading branch information
trippyone committed Jun 26, 2024
1 parent 58c3484 commit 0b6d3d3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
17 changes: 10 additions & 7 deletions Fika.Core/FikaPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public class FikaPlugin : BaseUnityPlugin
public static ConfigEntry<int> UDPPort { get; set; }
public static ConfigEntry<bool> UseUPnP { get; set; }
public static ConfigEntry<bool> UseNatPunching { get; set; }
public static ConfigEntry<int> NatPunchPort { get; set; }
public static ConfigEntry<int> ConnectionTimeout { get; set; }

// Gameplay
Expand Down Expand Up @@ -396,19 +397,21 @@ private void SetupConfig()

// Network

NativeSockets = Config.Bind(section: "Network", "Native Sockets", false, new ConfigDescription("Use NativeSockets for gameplay traffic. This uses direct socket calls for send/receive to drastically increase speed and reduce GC pressure. Only for Windows/Linux and might not always work.", tags: new ConfigurationManagerAttributes() { Order = 8 }));
NativeSockets = Config.Bind(section: "Network", "Native Sockets", false, new ConfigDescription("Use NativeSockets for gameplay traffic. This uses direct socket calls for send/receive to drastically increase speed and reduce GC pressure. Only for Windows/Linux and might not always work.", tags: new ConfigurationManagerAttributes() { Order = 9 }));

ForceIP = Config.Bind("Network", "Force IP", "", new ConfigDescription("Forces the server when hosting to use this IP when broadcasting to the backend instead of automatically trying to fetch it. Leave empty to disable.", tags: new ConfigurationManagerAttributes() { Order = 7 }));
ForceIP = Config.Bind("Network", "Force IP", "", new ConfigDescription("Forces the server when hosting to use this IP when broadcasting to the backend instead of automatically trying to fetch it. Leave empty to disable.", tags: new ConfigurationManagerAttributes() { Order = 8 }));

ForceBindIP = Config.Bind("Network", "Force Bind IP", "", new ConfigDescription("Forces the server when hosting to use this local IP when starting the server. Useful if you are hosting on a VPN.", new AcceptableValueList<string>(GetLocalAddresses()), new ConfigurationManagerAttributes() { Order = 6 }));
ForceBindIP = Config.Bind("Network", "Force Bind IP", "", new ConfigDescription("Forces the server when hosting to use this local IP when starting the server. Useful if you are hosting on a VPN.", new AcceptableValueList<string>(GetLocalAddresses()), new ConfigurationManagerAttributes() { Order = 7 }));

AutoRefreshRate = Config.Bind("Network", "Auto Server Refresh Rate", 10f, new ConfigDescription("Every X seconds the client will ask the server for the list of matches while at the lobby screen.", new AcceptableValueRange<float>(3f, 60f), new ConfigurationManagerAttributes() { Order = 5 }));
AutoRefreshRate = Config.Bind("Network", "Auto Server Refresh Rate", 10f, new ConfigDescription("Every X seconds the client will ask the server for the list of matches while at the lobby screen.", new AcceptableValueRange<float>(3f, 60f), new ConfigurationManagerAttributes() { Order = 6 }));

UDPPort = Config.Bind("Network", "UDP Port", 25565, new ConfigDescription("Port to use for UDP gameplay packets.", tags: new ConfigurationManagerAttributes() { Order = 4 }));
UDPPort = Config.Bind("Network", "UDP Port", 25565, new ConfigDescription("Port to use for UDP gameplay packets.", tags: new ConfigurationManagerAttributes() { Order = 5 }));

UseUPnP = Config.Bind("Network", "Use UPnP", false, new ConfigDescription("Attempt to open ports using UPnP. Useful if you cannot open ports yourself but the router supports UPnP.", tags: new ConfigurationManagerAttributes() { Order = 3 }));
UseUPnP = Config.Bind("Network", "Use UPnP", false, new ConfigDescription("Attempt to open ports using UPnP. Useful if you cannot open ports yourself but the router supports UPnP.", tags: new ConfigurationManagerAttributes() { Order = 4 }));

UseNatPunching = Config.Bind("Network", "Use NAT Punching", false, new ConfigDescription("Use NAT punching as a NAT traversal method for hosting a raid. Only works with fullcone NAT type routers. UPnP, Force IP and Force Bind IP are disabled in this mode.", tags: new ConfigurationManagerAttributes() { Order = 2 }));
UseNatPunching = Config.Bind("Network", "Use NAT Punching", false, new ConfigDescription("Use NAT punching as a NAT traversal method for hosting a raid. Only works with fullcone NAT type routers and requires NatPunchServer to be running on the AKI server. UPnP, Force IP and Force Bind IP are disabled in this mode.", tags: new ConfigurationManagerAttributes() { Order = 3 }));

NatPunchPort = Config.Bind("Network", "NAT Punch Port", 6790, new ConfigDescription("Port to use to connect to the FikaNatPunchServer.", tags: new ConfigurationManagerAttributes() { Order = 2 }));

ConnectionTimeout = Config.Bind("Network", "Connection Timeout", 15, new ConfigDescription("How long it takes for a connection to be considered dropped if no packets are received.", new AcceptableValueRange<int>(5, 60), new ConfigurationManagerAttributes() { Order = 1 }));

Expand Down
2 changes: 1 addition & 1 deletion Fika.Core/Networking/FikaPingingClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public bool Init(string serverId)
NetClient.NatPunchModule.Init(this);

string natHost = RequestHandler.Host.Replace("http://", "").Split(':')[0];
int natPort = 6970;
int natPort = FikaPlugin.NatPunchPort.Value;

IPEndPoint natIPEndPoint = new IPEndPoint(IPAddress.Parse(natHost), natPort);

Expand Down
6 changes: 3 additions & 3 deletions Fika.Core/Networking/FikaServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ public async Task Init()

natIntroduceRoutineCts = new CancellationTokenSource();

string host = RequestHandler.Host.Replace("http://", "").Split(':')[0];
int port = 6970;
string natHost = RequestHandler.Host.Replace("http://", "").Split(':')[0];
int natPort = FikaPlugin.NatPunchPort.Value;

IPEndPoint natServerIPEndPoint = new IPEndPoint(IPAddress.Parse(host), port);
IPEndPoint natServerIPEndPoint = new IPEndPoint(IPAddress.Parse(natHost), natPort);

Task natIntroduceTask = Task.Run(() => NatIntroduceRoutine(natServerIPEndPoint, natIntroduceRoutineCts.Token));
}
Expand Down

0 comments on commit 0b6d3d3

Please sign in to comment.