diff --git a/Barotrauma/BarotraumaServer/ServerSource/GameMain.cs b/Barotrauma/BarotraumaServer/ServerSource/GameMain.cs index 579ba3550..253c2ee38 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/GameMain.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/GameMain.cs @@ -12,6 +12,7 @@ using System.Reflection; using System.Threading; using System.Xml.Linq; using MoonSharp.Interpreter; +using System.Net; namespace Barotrauma { @@ -221,6 +222,7 @@ namespace Barotrauma int maxPlayers = 10; int? ownerKey = null; UInt64 steamId = 0; + IPAddress listenIp = IPAddress.Any; XDocument doc = XMLExtensions.TryLoadXml(ServerSettings.SettingsFile); if (doc?.Root == null) @@ -254,6 +256,12 @@ namespace Barotrauma name = CommandLineArgs[i + 1]; i++; break; + case "-ip": + if (IPAddress.TryParse(CommandLineArgs[i + 1], out IPAddress address)) + listenIp = address; + else + DebugConsole.ThrowError($"Invalid Ip Address '{CommandLineArgs[i + 1]}'."); + break; case "-port": int.TryParse(CommandLineArgs[i + 1], out port); i++; @@ -302,6 +310,7 @@ namespace Barotrauma Server = new GameServer( name, + listenIp, port, queryPort, publiclyVisible, diff --git a/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs b/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs index c6ff81793..3bd5e1c12 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs @@ -12,6 +12,7 @@ using System.Linq; using System.Threading; using System.Xml.Linq; using MoonSharp.Interpreter; +using System.Net; namespace Barotrauma.Networking { @@ -114,7 +115,7 @@ namespace Barotrauma.Networking private readonly int? ownerKey; private readonly UInt64? ownerSteamId; - public GameServer(string name, int port, int queryPort = 0, bool isPublic = false, string password = "", bool attemptUPnP = false, int maxPlayers = 10, int? ownKey = null, UInt64? steamId = null) + public GameServer(string name, IPAddress listenIp, int port, int queryPort = 0, bool isPublic = false, string password = "", bool attemptUPnP = false, int maxPlayers = 10, int? ownKey = null, UInt64? steamId = null) { name = name.Replace(":", ""); name = name.Replace(";", ""); @@ -127,7 +128,7 @@ namespace Barotrauma.Networking LastClientListUpdateID = 0; - serverSettings = new ServerSettings(this, name, port, queryPort, maxPlayers, isPublic, attemptUPnP); + serverSettings = new ServerSettings(this, name, port, queryPort, maxPlayers, isPublic, attemptUPnP, listenIp); KarmaManager.SelectPreset(serverSettings.KarmaPreset); serverSettings.SetPassword(password); diff --git a/Barotrauma/BarotraumaServer/ServerSource/Networking/Primitives/Peers/Server/LidgrenServerPeer.cs b/Barotrauma/BarotraumaServer/ServerSource/Networking/Primitives/Peers/Server/LidgrenServerPeer.cs index 8daa8ad3d..01a70a36e 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Networking/Primitives/Peers/Server/LidgrenServerPeer.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Networking/Primitives/Peers/Server/LidgrenServerPeer.cs @@ -37,7 +37,8 @@ namespace Barotrauma.Networking AutoExpandMTU = false, MaximumConnections = NetConfig.MaxPlayers * 2, EnableUPnP = serverSettings.EnableUPnP, - Port = serverSettings.Port + Port = serverSettings.Port, + LocalAddress = serverSettings.ListenIPAddress }; netPeerConfiguration.DisableMessageType(NetIncomingMessageType.DebugMessage | diff --git a/Barotrauma/BarotraumaServer/ServerSource/Networking/SteamManager.cs b/Barotrauma/BarotraumaServer/ServerSource/Networking/SteamManager.cs index beb842ec4..eda026cab 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Networking/SteamManager.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Networking/SteamManager.cs @@ -16,7 +16,8 @@ namespace Barotrauma.Steam { GamePort = (ushort)server.Port, QueryPort = isPublic ? (ushort)server.QueryPort : (ushort)0, - Mode = isPublic ? Steamworks.InitServerMode.Authentication : Steamworks.InitServerMode.NoAuthentication + Mode = isPublic ? Steamworks.InitServerMode.Authentication : Steamworks.InitServerMode.NoAuthentication, + IpAddress = server.ServerSettings.ListenIPAddress }; //options.QueryShareGamePort(); diff --git a/Barotrauma/BarotraumaShared/SharedSource/Networking/ServerSettings.cs b/Barotrauma/BarotraumaShared/SharedSource/Networking/ServerSettings.cs index 4d335dc73..de713ce8f 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Networking/ServerSettings.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Networking/ServerSettings.cs @@ -273,7 +273,7 @@ namespace Barotrauma.Networking partial void InitProjSpecific(); - public ServerSettings(NetworkMember networkMember, string serverName, int port, int queryPort, int maxPlayers, bool isPublic, bool enableUPnP) + public ServerSettings(NetworkMember networkMember, string serverName, int port, int queryPort, int maxPlayers, bool isPublic, bool enableUPnP, IPAddress listenIp) { ServerLog = new ServerLog(serverName); @@ -288,6 +288,7 @@ namespace Barotrauma.Networking InitProjSpecific(); ServerName = serverName; + ListenIPAddress = listenIp; Port = port; QueryPort = queryPort; EnableUPnP = enableUPnP; @@ -359,6 +360,8 @@ namespace Barotrauma.Networking public int QueryPort; + public IPAddress ListenIPAddress; + public bool EnableUPnP; public ServerLog ServerLog;