Skip to content

Commit

Permalink
Merge pull request #93 from ArchangelWTF/fix/small-changes
Browse files Browse the repository at this point in the history
Various small changes
  • Loading branch information
Lacyway authored Jul 14, 2024
2 parents 0a41a1f + f5a51fa commit 8e4dc07
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
31 changes: 31 additions & 0 deletions Fika.Core/Console/FikaCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Fika.Core.Coop.GameMode;
using Fika.Core.Coop.Players;
using Fika.Core.Coop.Utils;
using System.Collections.Generic;

namespace Fika.Core.Console
{
Expand Down Expand Up @@ -113,6 +114,36 @@ public static void Extract()

coopGame.Extract(localPlayer, null);
}

[ConsoleCommand("despawnallai", "", null, "Despawns all AI Bots", [])]
public static void DespawnAllAI()
{
if (Singleton<IFikaGame>.Instance is CoopGame game)
{
if (!FikaBackendUtils.IsServer)
{
ConsoleScreen.LogWarning("You are not the host.");
return;
}

CoopHandler.TryGetCoopHandler(out CoopHandler coopHandler);

List<IPlayer> Bots = new List<IPlayer>(game.BotsController.Players);

foreach (Player bot in Bots)
{
if (bot.AIData.BotOwner == null)
{
continue;
}

ConsoleScreen.Log($"Despawning: {bot.Profile.Nickname}");

game.DespawnBot(coopHandler, bot);
}
}
}

#endif

[ConsoleCommand("debug", "", null, "Toggle debug window", [])]
Expand Down
5 changes: 5 additions & 0 deletions Fika.Core/Coop/Components/CoopHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using EFT;
using EFT.Interactive;
using EFT.InventoryLogic;
using EFT.UI;
using Fika.Core.Coop.BTR;
using Fika.Core.Coop.GameMode;
using Fika.Core.Coop.Players;
Expand Down Expand Up @@ -196,6 +197,10 @@ void ProcessQuitting()

if (FikaPlugin.ExtractKey.Value.IsDown() && quitState != EQuitState.NONE && !requestQuitGame)
{
//Log to both the in-game console as well as into the BepInEx logfile
ConsoleScreen.Log($"{FikaPlugin.ExtractKey.Value} pressed, attempting to extract!");
Logger.LogInfo($"{FikaPlugin.ExtractKey.Value} pressed, attempting to extract!");

requestQuitGame = true;
CoopGame coopGame = (CoopGame)Singleton<IFikaGame>.Instance;

Expand Down
3 changes: 1 addition & 2 deletions Fika.Core/Coop/GameMode/CoopGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,8 @@ private bool TryDespawnFurthestBot(Profile profile, Vector3 position, CoopHandle
/// </summary>
/// <param name="coopHandler"></param>
/// <param name="bot">The bot to despawn</param>
private void DespawnBot(CoopHandler coopHandler, Player bot)
internal void DespawnBot(CoopHandler coopHandler, Player bot)
{
IBotGame botGame = Singleton<IBotGame>.Instance;
BotOwner botOwner = bot.AIData.BotOwner;

BotsController.Bots.Remove(botOwner);
Expand Down
20 changes: 19 additions & 1 deletion Fika.Core/Networking/FikaServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public async Task Init()

foreach (string ip in FikaPlugin.Instance.LocalIPs)
{
if (ip.StartsWith("192.168")) // need to add more cases here later, for now only check normal range...
if (ValidateLocalIP(ip))
{
Ips = [MyExternalIP, ip];
}
Expand All @@ -212,6 +212,24 @@ public async Task Init()
FikaEventDispatcher.DispatchEvent(new FikaServerCreatedEvent(this));
}

private bool ValidateLocalIP(string LocalIP)
{
if(LocalIP.StartsWith("192.168") || LocalIP.StartsWith("10"))
{
return true;
}

//Check for RFC1918's 20 bit block.
int[] ip = Array.ConvertAll(LocalIP.Split('.'), int.Parse);

if (ip[0] == 172 && (ip[1] >= 16 && ip[1] <= 31))
{
return true;
}

return false;
}

private async void NatIntroduceRoutine(string natPunchServerIP, int natPunchServerPort, string token, CancellationToken ct)
{
logger.LogInfo("NatIntroduceRoutine started.");
Expand Down

0 comments on commit 8e4dc07

Please sign in to comment.