Server Status Changes

- refactored the code to stop the server status cycling and to be more accurate.
This commit is contained in:
Brett Hewitson 2022-07-15 22:36:13 +10:00
parent c79ec023d8
commit 9e52ccbaa1
15 changed files with 321 additions and 236 deletions

View file

@ -252,84 +252,162 @@ namespace ServerManagerTool.Lib
{
case WatcherServerStatus.Unknown:
if (oldStatus != ServerStatus.Updating)
UpdateServerStatus(ServerStatus.Unknown, AvailabilityStatus.Unknown, false);
{
UpdateServerStatus(
ServerStatus.Unknown,
AvailabilityStatus.Unknown,
false);
}
if (this.motdIntervalTimer != null && this.motdIntervalTimer.Enabled)
if (this.motdIntervalTimer != null && this.motdIntervalTimer.Enabled)
{
this.motdIntervalTimer.Stop();
}
break;
case WatcherServerStatus.NotInstalled:
if (oldStatus != ServerStatus.Updating)
UpdateServerStatus(ServerStatus.Uninstalled, AvailabilityStatus.Unavailable, false);
{
UpdateServerStatus(
ServerStatus.Uninstalled,
AvailabilityStatus.Unavailable,
false);
}
if (this.motdIntervalTimer != null && this.motdIntervalTimer.Enabled)
if (this.motdIntervalTimer != null && this.motdIntervalTimer.Enabled)
{
this.motdIntervalTimer.Stop();
}
break;
case WatcherServerStatus.Stopped:
if (oldStatus != ServerStatus.Updating)
UpdateServerStatus(ServerStatus.Stopped, AvailabilityStatus.Unavailable, oldStatus == ServerStatus.Initializing || oldStatus == ServerStatus.Running || oldStatus == ServerStatus.Stopping);
{
UpdateServerStatus(
ServerStatus.Stopped,
AvailabilityStatus.Unavailable,
oldStatus == ServerStatus.Initializing || oldStatus == ServerStatus.Running || oldStatus == ServerStatus.Stopping);
}
if (this.motdIntervalTimer != null && this.motdIntervalTimer.Enabled)
if (this.motdIntervalTimer != null && this.motdIntervalTimer.Enabled)
{
this.motdIntervalTimer.Stop();
}
break;
case WatcherServerStatus.Initializing:
if (oldStatus != ServerStatus.Stopping)
UpdateServerStatus(ServerStatus.Initializing, AvailabilityStatus.Unavailable, oldStatus != ServerStatus.Initializing && oldStatus != ServerStatus.Unknown);
{
UpdateServerStatus(
ServerStatus.Initializing,
AvailabilityStatus.Unavailable,
oldStatus != ServerStatus.Initializing && oldStatus != ServerStatus.Unknown);
}
if (this.motdIntervalTimer != null && this.motdIntervalTimer.Enabled)
if (this.motdIntervalTimer != null && this.motdIntervalTimer.Enabled)
{
this.motdIntervalTimer.Stop();
}
break;
case WatcherServerStatus.RunningLocalCheck:
case WatcherServerStatus.LocalSuccess:
if (oldStatus != ServerStatus.Stopping)
{
UpdateServerStatus(ServerStatus.Running, oldAvailability != AvailabilityStatus.Available ? AvailabilityStatus.LocalOnly : AvailabilityStatus.Available, oldStatus != ServerStatus.Running && oldStatus != ServerStatus.Unknown);
UpdateServerStatus(
ServerStatus.Running,
AvailabilityStatus.LocalOnly,
oldStatus != ServerStatus.Running && oldStatus != ServerStatus.Unknown);
if (this.ProfileSnapshot.MOTDIntervalEnabled && this.motdIntervalTimer != null && !this.motdIntervalTimer.Enabled)
if (this.ProfileSnapshot.MOTDIntervalEnabled && this.motdIntervalTimer != null && !this.motdIntervalTimer.Enabled)
{
this.motdIntervalTimer.Start();
}
}
else
{
if (this.motdIntervalTimer != null && this.motdIntervalTimer.Enabled)
{
this.motdIntervalTimer.Stop();
}
}
break;
case WatcherServerStatus.RunningExternalCheck:
case WatcherServerStatus.ExternalSkipped:
if (oldStatus != ServerStatus.Stopping)
{
UpdateServerStatus(ServerStatus.Running, AvailabilityStatus.PublicOnly, oldStatus != ServerStatus.Running && oldStatus != ServerStatus.Unknown);
UpdateServerStatus(
ServerStatus.Running,
oldAvailability >= AvailabilityStatus.PublicOnly ? AvailabilityStatus.PublicOnly : AvailabilityStatus.LocalOnly,
oldStatus != ServerStatus.Running && oldStatus != ServerStatus.Unknown);
if (this.ProfileSnapshot.MOTDIntervalEnabled && this.motdIntervalTimer != null && !this.motdIntervalTimer.Enabled)
if (this.ProfileSnapshot.MOTDIntervalEnabled && this.motdIntervalTimer != null && !this.motdIntervalTimer.Enabled)
{
this.motdIntervalTimer.Start();
}
}
else
{
if (this.motdIntervalTimer != null && this.motdIntervalTimer.Enabled)
{
this.motdIntervalTimer.Stop();
}
}
break;
case WatcherServerStatus.ExternalSuccess:
if (oldStatus != ServerStatus.Stopping)
{
UpdateServerStatus(
ServerStatus.Running,
AvailabilityStatus.PublicOnly,
oldStatus != ServerStatus.Running && oldStatus != ServerStatus.Unknown);
if (this.ProfileSnapshot.MOTDIntervalEnabled && this.motdIntervalTimer != null && !this.motdIntervalTimer.Enabled)
{
this.motdIntervalTimer.Start();
}
}
else
{
if (this.motdIntervalTimer != null && this.motdIntervalTimer.Enabled)
{
this.motdIntervalTimer.Stop();
}
}
break;
case WatcherServerStatus.Published:
if (oldStatus != ServerStatus.Stopping)
{
UpdateServerStatus(ServerStatus.Running, AvailabilityStatus.Available, oldStatus != ServerStatus.Running && oldStatus != ServerStatus.Unknown);
UpdateServerStatus(
ServerStatus.Running,
AvailabilityStatus.Available,
oldStatus != ServerStatus.Running && oldStatus != ServerStatus.Unknown);
if (this.ProfileSnapshot.MOTDIntervalEnabled && this.motdIntervalTimer != null && !this.motdIntervalTimer.Enabled)
if (this.ProfileSnapshot.MOTDIntervalEnabled && this.motdIntervalTimer != null && !this.motdIntervalTimer.Enabled)
{
this.motdIntervalTimer.Start();
}
}
else
{
if (this.motdIntervalTimer != null && this.motdIntervalTimer.Enabled)
{
this.motdIntervalTimer.Stop();
}
}
break;
default:
if (this.motdIntervalTimer != null && this.motdIntervalTimer.Enabled)
if (this.motdIntervalTimer != null && this.motdIntervalTimer.Enabled)
{
this.motdIntervalTimer.Stop();
}
break;
}

View file

@ -150,52 +150,52 @@ namespace ServerManagerTool.Lib
var currentStatus = WatcherServerStatus.Initializing;
//
// If the process was running do we then perform network checks.
//
Logger.Info($"{nameof(DoServerStatusUpdateAsync)} Checking server local network status at {registration.LocalEndpoint}");
Logger.Info($"{nameof(DoServerStatusUpdateAsync)} Checking server local (directly) status at {registration.LocalEndpoint}");
// get the server information direct from the server using local connection.
// get the server information direct from the server using local endpoint.
var serverStatus = GetLocalNetworkStatus(registration.LocalEndpoint, out ServerInfo localInfo, out int onlinePlayerCount);
if (serverStatus)
{
currentStatus = WatcherServerStatus.RunningLocalCheck;
currentStatus = WatcherServerStatus.LocalSuccess;
//
// Now that it's running, we can check the publication status.
//
Logger.Info($"{nameof(DoServerStatusUpdateAsync)} Checking server public (directly) status at {registration.PublicEndpoint}");
// get the server information direct from the server using public connection.
// get the server information direct from the server using public endpoint.
serverStatus = GetPublicNetworkStatusDirectly(registration.PublicEndpoint);
// check if the server returned the information.
if (!serverStatus)
if (serverStatus)
{
_nextExternalStatusQuery[registrationKey] = DateTime.MinValue;
currentStatus = WatcherServerStatus.Published;
}
else if (!string.IsNullOrWhiteSpace(Config.Default.ServerStatusUrlFormat))
{
// server did not return any information
var nextExternalStatusQuery = _nextExternalStatusQuery.ContainsKey(registrationKey) ? _nextExternalStatusQuery[registrationKey] : DateTime.MinValue;
if (DateTime.Now >= nextExternalStatusQuery)
{
currentStatus = WatcherServerStatus.RunningExternalCheck;
Logger.Info($"{nameof(DoServerStatusUpdateAsync)} Checking server public (externally) status at {registration.PublicEndpoint}");
if (!string.IsNullOrWhiteSpace(Config.Default.ServerStatusUrlFormat))
// get the server information direct from the server using external endpoint.
var url = string.Format(Config.Default.ServerStatusUrlFormat, Config.Default.ServerManagerCode, App.Instance.Version, registration.PublicEndpoint.Address, registration.PublicEndpoint.Port);
var uri = new Uri(url);
serverStatus = await GetPublicNetworkStatusViaAPIAsync(uri, registration.PublicEndpoint);
var remoteStatusQueryDelay = serverStatus
? Config.Default.ServerStatusWatcher_RemoteStatusQueryDelay
: 15000;
_nextExternalStatusQuery[registrationKey] = DateTime.Now.AddMilliseconds(remoteStatusQueryDelay);
if (serverStatus)
{
Logger.Info($"{nameof(DoServerStatusUpdateAsync)} Checking server public (via api) status at {registration.PublicEndpoint}");
// get the server information direct from the server using external connection.
var uri = new Uri(string.Format(Config.Default.ServerStatusUrlFormat, Config.Default.ServerManagerCode, App.Instance.Version, registration.PublicEndpoint.Address, registration.PublicEndpoint.Port));
serverStatus = await GetPublicNetworkStatusViaAPIAsync(uri, registration.PublicEndpoint);
currentStatus = WatcherServerStatus.ExternalSuccess;
}
_nextExternalStatusQuery[registrationKey] = DateTime.Now.AddMilliseconds(Config.Default.ServerStatusWatcher_RemoteStatusQueryDelay);
}
}
// check if the server returned the information.
if (serverStatus)
{
currentStatus = WatcherServerStatus.Published;
else
{
currentStatus = WatcherServerStatus.ExternalSkipped;
}
}
}