Skip to content

Commit

Permalink
Make unknown ports not throw
Browse files Browse the repository at this point in the history
  • Loading branch information
Windows10CE committed Sep 12, 2021
1 parent dbc2d66 commit 4d18979
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions PathfinderAPI/Port/PortManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx.Logging;
using Pathfinder.Event;
using Hacknet;
using Hacknet.Security;
Expand Down Expand Up @@ -61,7 +62,7 @@ public static void LoadPortsFromString(Computer comp, string portString, bool cl
{
if (clearExisting)
comp.ClearPorts();
foreach (var port in portString.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
foreach (var port in portString.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries))
{
var portParts = port.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
if (portParts.Length == 1)
Expand Down Expand Up @@ -102,7 +103,12 @@ public static void LoadPortsFromStringVanilla(Computer comp, string portsList)
if (!int.TryParse(port, out var portNum))
throw new FormatException($"Failed to parse port number from '{port}'");
var data = GetPortDataFromNumber(portNum);
comp.AddPort(data?.Clone() ?? throw new ArgumentException($"No port has the default {port}"));
if (data == null)
{
Logger.Log(LogLevel.Warning, $"{comp.idName} has port {port}, which does not exist");
continue;
}
comp.AddPort(data.Clone());
}
}

Expand Down

0 comments on commit 4d18979

Please sign in to comment.