diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index c53d12b247..ee9d56ce30 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -969,7 +969,8 @@ namespace OpenRA { Name = "Skirmish Game", Map = map, - AdvertiseOnline = false + AdvertiseOnline = false, + AdvertiseOnLocalNetwork = !isSkirmish }; // Always connect to local games using the same loopback connection diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index d634ef911b..0e2f937def 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -53,6 +53,9 @@ namespace OpenRA [Desc("Reports the game to the master server list.")] public bool AdvertiseOnline = true; + [Desc("Reports the game on the local area network.")] + public bool AdvertiseOnLocalNetwork = true; + [Desc("Locks the game with a password.")] public string Password = ""; diff --git a/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs b/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs index 3d6d30c218..d9d6b3cd71 100644 --- a/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs +++ b/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs @@ -48,13 +48,14 @@ namespace OpenRA.Mods.Common.Server [FluentReference] const string GameOffline = "notification-game-offline"; - static readonly Beacon LanGameBeacon; + static readonly ushort LanAdvertisePort = (ushort)new Random(DateTime.Now.Millisecond).Next(2048, 60000); static readonly Dictionary MasterServerErrors = new() { { 1, NoPortForward }, { 2, BlacklistedTitle } }; + Beacon lanGameBeacon; long lastPing = 0; long lastChanged = 0; bool isInitialPing = true; @@ -62,14 +63,16 @@ namespace OpenRA.Mods.Common.Server volatile bool isBusy; readonly Queue masterServerMessages = []; - static MasterServerPinger() + void CreateLanGameBeacon() { try { - LanGameBeacon = new Beacon("OpenRALANGame", (ushort)new Random(DateTime.Now.Millisecond).Next(2048, 60000)); + lanGameBeacon?.Stop(); + lanGameBeacon = new Beacon("OpenRALANGame", LanAdvertisePort); } catch (Exception ex) { + lanGameBeacon = null; Log.Write("server", "BeaconLib.Beacon: " + ex.Message); } } @@ -83,27 +86,34 @@ namespace OpenRA.Mods.Common.Server // Update the master server and LAN clients if something has changed // Note that isBusy is set while the master server ping is running on a // background thread, and limits LAN pings as well as master server pings for simplicity. - if (!isBusy && ((lastChanged > lastPing && Game.RunTime - lastPing > RateLimitInterval) || isInitialPing)) + if ((server.Settings.AdvertiseOnline || server.Settings.AdvertiseOnLocalNetwork) + && !isBusy && ((lastChanged > lastPing && Game.RunTime - lastPing > RateLimitInterval) || isInitialPing)) { var gs = new GameServer(server); if (server.Settings.AdvertiseOnline) UpdateMasterServer(server, gs.ToPOSTData(false)); - if (LanGameBeacon != null) - LanGameBeacon.BeaconData = gs.ToPOSTData(true); + if (server.Settings.AdvertiseOnLocalNetwork && lanGameBeacon != null) + lanGameBeacon.BeaconData = gs.ToPOSTData(true); lastPing = Game.RunTime; } - lock (masterServerMessages) - while (masterServerMessages.Count > 0) - server.SendFluentMessage(masterServerMessages.Dequeue()); + if (server.Settings.AdvertiseOnline) + lock (masterServerMessages) + while (masterServerMessages.Count > 0) + server.SendFluentMessage(masterServerMessages.Dequeue()); } void INotifyServerStart.ServerStarted(S server) { - if (server.IsMultiplayer && LanGameBeacon != null) - LanGameBeacon.Start(); + if (server.IsMultiplayer && server.Settings.AdvertiseOnLocalNetwork) + { + if (lanGameBeacon == null) + CreateLanGameBeacon(); + + lanGameBeacon?.Start(); + } } void INotifyServerShutdown.ServerShutdown(S server) @@ -115,7 +125,8 @@ namespace OpenRA.Mods.Common.Server UpdateMasterServer(server, gameServer.ToPOSTData(false)); } - LanGameBeacon?.Stop(); + lanGameBeacon?.Stop(); + lanGameBeacon = null; } public void LobbyInfoSynced(S server) @@ -130,7 +141,8 @@ namespace OpenRA.Mods.Common.Server public void GameEnded(S server) { - LanGameBeacon?.Stop(); + lanGameBeacon?.Stop(); + lanGameBeacon = null; lastChanged = Game.RunTime; } diff --git a/launch-dedicated.cmd b/launch-dedicated.cmd index 9cff0b8fb7..a41c75fa74 100644 --- a/launch-dedicated.cmd +++ b/launch-dedicated.cmd @@ -7,6 +7,7 @@ set Mod=ra set Map="" set ListenPort=1234 set AdvertiseOnline=True +set AdvertiseOnLocalNetwork=True set Password="" set RecordReplays=False @@ -26,6 +27,6 @@ set SupportDir="" :loop -bin\OpenRA.Server.exe Engine.EngineDir=".." Game.Mod=%Mod% Server.Name=%Name% Server.Map=%Map% Server.ListenPort=%ListenPort% Server.AdvertiseOnline=%AdvertiseOnline% Server.EnableSingleplayer=%EnableSingleplayer% Server.Password=%Password% Server.RecordReplays=%RecordReplays% Server.RequireAuthentication=%RequireAuthentication% Server.ProfileIDBlacklist=%ProfileIDBlacklist% Server.ProfileIDWhitelist=%ProfileIDWhitelist% Server.EnableSyncReports=%EnableSyncReports% Server.EnableGeoIP=%EnableGeoIP% Server.EnableLintChecks=%EnableLintChecks% Server.ShareAnonymizedIPs=%ShareAnonymizedIPs% Server.FloodLimitJoinCooldown=%FloodLimitJoinCooldown% Engine.SupportDir=%SupportDir% +bin\OpenRA.Server.exe Engine.EngineDir=".." Game.Mod=%Mod% Server.Name=%Name% Server.Map=%Map% Server.ListenPort=%ListenPort% Server.AdvertiseOnline=%AdvertiseOnline% Server.AdvertiseOnLocalNetwork=%AdvertiseOnLocalNetwork% Server.EnableSingleplayer=%EnableSingleplayer% Server.Password=%Password% Server.RecordReplays=%RecordReplays% Server.RequireAuthentication=%RequireAuthentication% Server.ProfileIDBlacklist=%ProfileIDBlacklist% Server.ProfileIDWhitelist=%ProfileIDWhitelist% Server.EnableSyncReports=%EnableSyncReports% Server.EnableGeoIP=%EnableGeoIP% Server.EnableLintChecks=%EnableLintChecks% Server.ShareAnonymizedIPs=%ShareAnonymizedIPs% Server.FloodLimitJoinCooldown=%FloodLimitJoinCooldown% Engine.SupportDir=%SupportDir% goto loop diff --git a/launch-dedicated.sh b/launch-dedicated.sh index 2f728e81fc..2b2753102d 100755 --- a/launch-dedicated.sh +++ b/launch-dedicated.sh @@ -15,6 +15,7 @@ Mod="${Mod:-"ra"}" Map="${Map:-""}" ListenPort="${ListenPort:-"1234"}" AdvertiseOnline="${AdvertiseOnline:-"True"}" +AdvertiseOnLocalNetwork="${AdvertiseOnLocalNetwork:-"True"}" Password="${Password:-""}" RecordReplays="${RecordReplays:-"False"}" @@ -38,6 +39,7 @@ while true; do Server.Map="$Map" \ Server.ListenPort="$ListenPort" \ Server.AdvertiseOnline="$AdvertiseOnline" \ + Server.AdvertiseOnLocalNetwork="$AdvertiseOnLocalNetwork" \ Server.EnableSingleplayer="$EnableSingleplayer" \ Server.Password="$Password" \ Server.RecordReplays="$RecordReplays" \