Catch and ignore BeaconLib errors

This commit is contained in:
rob-v
2017-05-25 00:45:16 +02:00
committed by Paul Chote
parent e1b7fc2617
commit 9a9920e4af
2 changed files with 29 additions and 7 deletions

View File

@@ -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. // 3 minutes. Server has a 5 minute TTL for games, so give ourselves a bit of leeway.
const int MasterPingInterval = 60 * 3; 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<int, string> MasterServerErrors = new Dictionary<int, string>() static readonly Dictionary<int, string> MasterServerErrors = new Dictionary<int, string>()
{ {
{ 1, "Server port is not accessible from the internet." }, { 1, "Server port is not accessible from the internet." },
@@ -40,6 +40,18 @@ namespace OpenRA.Mods.Common.Server
volatile bool isBusy; volatile bool isBusy;
Queue<string> masterServerMessages = new Queue<string>(); Queue<string> masterServerMessages = new Queue<string>();
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) public void Tick(S server)
{ {
if ((Game.RunTime - lastPing > MasterPingInterval * 1000) || isInitialPing) if ((Game.RunTime - lastPing > MasterPingInterval * 1000) || isInitialPing)
@@ -52,7 +64,7 @@ namespace OpenRA.Mods.Common.Server
public void ServerStarted(S server) public void ServerStarted(S server)
{ {
if (!server.Ip.Equals(IPAddress.Loopback)) if (!server.Ip.Equals(IPAddress.Loopback) && LanGameBeacon != null)
LanGameBeacon.Start(); LanGameBeacon.Start();
} }
@@ -68,7 +80,9 @@ namespace OpenRA.Mods.Common.Server
public void GameEnded(S server) public void GameEnded(S server)
{ {
LanGameBeacon.Stop(); if (LanGameBeacon != null)
LanGameBeacon.Stop();
PublishGame(server); 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(); 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); 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) void UpdateMasterServer(S server, int numPlayers, int numSlots, int numBots, int numSpectators, Manifest mod, bool passwordProtected, string[] clients)

View File

@@ -112,9 +112,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Game.LoadWidget(null, "GLOBALCHAT_PANEL", widget.Get("GLOBALCHAT_ROOT"), new WidgetArgs()); Game.LoadWidget(null, "GLOBALCHAT_PANEL", widget.Get("GLOBALCHAT_ROOT"), new WidgetArgs());
lanGameLocations = new List<BeaconLocation>(); lanGameLocations = new List<BeaconLocation>();
lanGameProbe = new Probe("OpenRALANGame"); try
lanGameProbe.BeaconsUpdated += locations => lanGameLocations = locations; {
lanGameProbe.Start(); lanGameProbe = new Probe("OpenRALANGame");
lanGameProbe.BeaconsUpdated += locations => lanGameLocations = locations;
lanGameProbe.Start();
}
catch (Exception ex)
{
Log.Write("debug", "BeaconLib.Probe: " + ex.Message);
}
RefreshServerList(); RefreshServerList();