Skip to content

Commit

Permalink
Only allowed predetermined IPs when binding
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed May 9, 2024
1 parent f5f96b3 commit fa6d5f1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 20 additions & 1 deletion Fika.Core/FikaPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
using Fika.Core.UI;
using Fika.Core.UI.Models;
using Fika.Core.UI.Patches;
using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Net;
using System.Text;
using UnityEngine;

Expand Down Expand Up @@ -156,6 +159,7 @@ public class FikaPlugin : BaseUnityPlugin
public static ConfigEntry<bool> NativeSockets { get; set; }
public static ConfigEntry<string> ForceIP { get; set; }
public static ConfigEntry<string> ForceBindIP { get; set; }
public static ConfigEntry<string> ForceBindIP2 { get; set; }
public static ConfigEntry<float> AutoRefreshRate { get; set; }
public static ConfigEntry<int> UDPPort { get; set; }
public static ConfigEntry<bool> UseUPnP { get; set; }
Expand Down Expand Up @@ -353,7 +357,7 @@ private void SetupConfig()

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 = 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. Leave empty to disable.", tags: new ConfigurationManagerAttributes() { Order = 5 }));
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. Leave empty to disable.",new AcceptableValueList<string>(GetLocalIPAddress()), 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 = 4 }));

Expand All @@ -370,6 +374,21 @@ private void SetupConfig()
ArmpitDamageMultiplier = Config.Bind("Gameplay", "Armpit Damage Multiplier", 1f, new ConfigDescription("X multiplier to damage taken on the armpits collider. 0.2 = 20%", new AcceptableValueRange<float>(0.2f, 1f), new ConfigurationManagerAttributes() { Order = 1 }));
}

private string[] GetLocalIPAddress()
{
IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
List<string> ips = [];
ips.Add("Disabled");
foreach (IPAddress ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
ips.Add(ip.ToString());
}
}
return [.. ips];
}

private void DisableSPTPatches()
{
// Disable these as they interfere with Fika
Expand Down
2 changes: 1 addition & 1 deletion Fika.Core/UI/Custom/MatchMakerUIScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private void CreateMatchMakerUI()
return;
}
}
if (FikaPlugin.ForceBindIP.Value != "")
if (FikaPlugin.ForceBindIP.Value != "Disabled")
{
if (!IPAddress.TryParse(FikaPlugin.ForceBindIP.Value, out _))
{
Expand Down

0 comments on commit fa6d5f1

Please sign in to comment.