From 9a9920e4af3c2311e933ec1954ae2b3c0160e563 Mon Sep 17 00:00:00 2001 From: rob-v Date: Thu, 25 May 2017 00:45:16 +0200 Subject: [PATCH] Catch and ignore BeaconLib errors --- .../ServerTraits/MasterServerPinger.cs | 23 +++++++++++++++---- .../Widgets/Logic/MultiplayerLogic.cs | 13 ++++++++--- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs b/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs index e37a5ade19..81d72c68cf 100644 --- a/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs +++ b/OpenRA.Mods.Common/ServerTraits/MasterServerPinger.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Server { // 3 minutes. Server has a 5 minute TTL for games, so give ourselves a bit of leeway. const int MasterPingInterval = 60 * 3; - static readonly Beacon LanGameBeacon = new Beacon("OpenRALANGame", (ushort)new Random(DateTime.Now.Millisecond).Next(2048, 60000)); + static readonly Beacon LanGameBeacon; static readonly Dictionary MasterServerErrors = new Dictionary() { { 1, "Server port is not accessible from the internet." }, @@ -40,6 +40,18 @@ namespace OpenRA.Mods.Common.Server volatile bool isBusy; Queue masterServerMessages = new Queue(); + static MasterServerPinger() + { + try + { + LanGameBeacon = new Beacon("OpenRALANGame", (ushort)new Random(DateTime.Now.Millisecond).Next(2048, 60000)); + } + catch (Exception ex) + { + Log.Write("server", "BeaconLib.Beacon: " + ex.Message); + } + } + public void Tick(S server) { if ((Game.RunTime - lastPing > MasterPingInterval * 1000) || isInitialPing) @@ -52,7 +64,7 @@ namespace OpenRA.Mods.Common.Server public void ServerStarted(S server) { - if (!server.Ip.Equals(IPAddress.Loopback)) + if (!server.Ip.Equals(IPAddress.Loopback) && LanGameBeacon != null) LanGameBeacon.Start(); } @@ -68,7 +80,9 @@ namespace OpenRA.Mods.Common.Server public void GameEnded(S server) { - LanGameBeacon.Stop(); + if (LanGameBeacon != null) + LanGameBeacon.Stop(); + PublishGame(server); } @@ -86,7 +100,8 @@ namespace OpenRA.Mods.Common.Server var clients = server.LobbyInfo.Clients.Where(c1 => c1.Bot == null).Select(c => Convert.ToBase64String(Encoding.UTF8.GetBytes(c.Name))).ToArray(); UpdateMasterServer(server, numPlayers, numSlots, numBots, numSpectators, mod, passwordProtected, clients); - UpdateLANGameBeacon(server, numPlayers, numSlots, numBots, numSpectators, mod, passwordProtected); + if (LanGameBeacon != null) + UpdateLANGameBeacon(server, numPlayers, numSlots, numBots, numSpectators, mod, passwordProtected); } void UpdateMasterServer(S server, int numPlayers, int numSlots, int numBots, int numSpectators, Manifest mod, bool passwordProtected, string[] clients) diff --git a/OpenRA.Mods.Common/Widgets/Logic/MultiplayerLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MultiplayerLogic.cs index 3c80ca0f69..f20f205b2b 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MultiplayerLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MultiplayerLogic.cs @@ -112,9 +112,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic Game.LoadWidget(null, "GLOBALCHAT_PANEL", widget.Get("GLOBALCHAT_ROOT"), new WidgetArgs()); lanGameLocations = new List(); - lanGameProbe = new Probe("OpenRALANGame"); - lanGameProbe.BeaconsUpdated += locations => lanGameLocations = locations; - lanGameProbe.Start(); + try + { + lanGameProbe = new Probe("OpenRALANGame"); + lanGameProbe.BeaconsUpdated += locations => lanGameLocations = locations; + lanGameProbe.Start(); + } + catch (Exception ex) + { + Log.Write("debug", "BeaconLib.Probe: " + ex.Message); + } RefreshServerList();