Skip to content

Commit b037cc8

Browse files
committed
Added -ip command line option
1 parent 07f48e7 commit b037cc8

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -807,8 +807,9 @@ public void SetClientRelayData(string ipAddress, ushort port, byte[] allocationI
807807

808808
// Command line options
809809
private const string k_OverridePortArg = "-port";
810+
private const string k_OverrideIpAddressArg = "-ip";
810811

811-
private bool ParseCommandLineOptions(out ushort port)
812+
private bool ParseCommandLineOptionsPort(out ushort port)
812813
{
813814
#if UNITY_SERVER && UNITY_DEDICATED_SERVER_ARGUMENTS_PRESENT
814815
if (UnityEngine.DedicatedServer.Arguments.Port != null)
@@ -827,6 +828,17 @@ private bool ParseCommandLineOptions(out ushort port)
827828
return false;
828829
}
829830

831+
private bool ParseCommandLineOptionsAddress(out string ipValue)
832+
{
833+
if (CommandLineOptions.Instance.GetArg(k_OverrideIpAddressArg) is string argValue)
834+
{
835+
ipValue = argValue;
836+
return true;
837+
}
838+
ipValue = default;
839+
return false;
840+
}
841+
830842
/// <summary>
831843
/// Sets IP and Port information. This will be ignored if using the Unity Relay and you should call <see cref="SetRelayServerData"/>
832844
/// </summary>
@@ -837,11 +849,16 @@ private bool ParseCommandLineOptions(out ushort port)
837849
public void SetConnectionData(string ipv4Address, ushort port, string listenAddress = null, bool forceOverrideCommandLineArgs = false)
838850
{
839851
m_HasForcedConnectionData = forceOverrideCommandLineArgs;
840-
if (!forceOverrideCommandLineArgs && ParseCommandLineOptions(out var commandLinePort))
852+
if (!forceOverrideCommandLineArgs && ParseCommandLineOptionsPort(out var commandLinePort))
841853
{
842854
port = commandLinePort;
843855
}
844856

857+
if (ParseCommandLineOptionsAddress(out var commandLineIp))
858+
{
859+
ipv4Address = commandLineIp;
860+
}
861+
845862
ConnectionData = new ConnectionAddressData
846863
{
847864
Address = ipv4Address,
@@ -1616,7 +1633,7 @@ public override void Initialize(NetworkManager networkManager = null)
16161633
m_NetworkManager = networkManager;
16171634

16181635
//If the port doesn't have a forced value and is set by a command line option, override it.
1619-
if (!m_HasForcedConnectionData && ParseCommandLineOptions(out var port))
1636+
if (!m_HasForcedConnectionData && ParseCommandLineOptionsAddress(out var port))
16201637
{
16211638
if (m_NetworkManager?.LogLevel <= LogLevel.Developer)
16221639
{

0 commit comments

Comments
 (0)