License: running server keeps running until the next restart

The configurable LicenseGraceHours setting is gone. If the master is down or
rejects the key, a running server now only warns and keeps running until the
next restart; a (re)start still works up to 72 h after the last confirmation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 20:45:38 +02:00
co-authored by Claude Opus 5.5
parent 816c538705
commit 1a2431db3a
9 changed files with 23 additions and 57 deletions
+5 -18
View File
@@ -287,7 +287,6 @@ public sealed class GameServer
if (result.Status == 0 || result.Status >= 500) Log("Master server not reachable - server is not listed right now.");
else if (result.Status >= 200 && result.Status < 300) ReportReachability(result);
}
CheckLicenseGrace();
if (!offline && now >= nextHeartbeat && heartbeat == null)
{
nextHeartbeat = now + HeartbeatSeconds;
@@ -1119,15 +1118,14 @@ public sealed class GameServer
/// <summary>Wann der Master den Schlüssel zuletzt bestätigt hat (setzt der Host beim Start).</summary>
public DateTime LicenseConfirmedUtc { get; set; } = DateTime.UtcNow;
/// <summary>Gesetzt, wenn der Server wegen fehlender Lizenzbestätigung gestoppt wurde.</summary>
public string LicenseStopReason { get; private set; }
/// <summary>Hinweis fürs Panel, solange der Master den Schlüssel nicht bestätigt (null = alles gut).</summary>
public string LicenseWarning { get; private set; }
DateTime nextLicenseWarning = DateTime.MinValue, lastLicenseCacheWrite = DateTime.MinValue;
TimeSpan LicenseGrace => TimeSpan.FromHours(Math.Clamp(config.LicenseGraceHours, 1, 24 * 30));
/// <summary>Antwort des Masters auf den Heartbeat auswerten - nie sofort stoppen.</summary>
/// <summary>
/// Antwort des Masters auf den Heartbeat auswerten. Ein laufender Server wird deswegen nie gestoppt - er läuft bis zum
/// nächsten Neustart weiter; erst beim Start wird die Lizenz wieder geprüft (siehe ServerHost).
/// </summary>
void OnLicenseResult(int status)
{
if (status >= 200 && status < 300)
@@ -1145,9 +1143,8 @@ public sealed class GameServer
}
bool rejected = status == 401 || status == 403;
var since = DateTime.UtcNow - LicenseConfirmedUtc;
var left = LicenseGrace - since;
LicenseWarning = (rejected ? "The master server rejects the license key" : "The master server is not reachable") +
$" (last confirmed {LicenseCache.Span(since)} ago) - the server keeps running for {LicenseCache.Span(left)}";
$" (last confirmed {LicenseCache.Span(since)} ago) - the server keeps running until the next restart";
if (DateTime.UtcNow >= nextLicenseWarning)
{
nextLicenseWarning = DateTime.UtcNow.AddMinutes(15);
@@ -1155,16 +1152,6 @@ public sealed class GameServer
}
}
/// <summary>Kulanzzeit abgelaufen? Dann den Gameserver stoppen (das Panel bleibt, der Host versucht es weiter).</summary>
void CheckLicenseGrace()
{
if (LicenseStopReason != null || DateTime.UtcNow - LicenseConfirmedUtc <= LicenseGrace) return;
LicenseStopReason = $"The license key could not be confirmed by the master server for {LicenseCache.Span(LicenseGrace)}";
Log(LicenseStopReason + " - stopping the game server. It starts again automatically as soon as the master confirms the key.");
stoppedBy = "the license check";
running = false;
}
public void RequestExit()
{
ExitRequested = true;