feat(console): add Core.Headless flag and guard the exit-pause prompt

This commit is contained in:
Kamron Batman 2026-07-15 21:40:17 -07:00
parent 7470cfd43c
commit a423905c6f
2 changed files with 27 additions and 1 deletions

View file

@ -0,0 +1,18 @@
using System;
namespace Server;
/// <summary>
/// Thrown when interactive console input is required but the server is running
/// headless (stdin is not a TTY). Rides the fatal-shutdown path.
/// </summary>
public sealed class HeadlessConsoleInputException : Exception
{
public HeadlessConsoleInputException(string context)
: base(
$"Interactive console input required but the server is headless (stdin is not a TTY). " +
$"Pre-supply the required configuration/save data. Prompt: {context}."
)
{
}
}

View file

@ -147,6 +147,8 @@ public static class Core
public static bool Closing => ClosingTokenSource.IsCancellationRequested;
public static bool Headless { get; private set; }
public static int GlobalUpdateRange { get; set; } = 18;
public static int GlobalMaxUpdateRange { get; set; } = 24;
@ -258,7 +260,7 @@ public static class Core
// ignored
}
if (!close)
if (!close && !Core.Headless)
{
Console.WriteLine("This exception is fatal, press return to exit");
ConsoleInputHandler.ReadLine();
@ -407,6 +409,12 @@ public static class Core
Console.CancelKeyPress += Console_CancelKeyPressed;
Headless = Console.IsInputRedirected;
if (Headless)
{
logger.Information("Headless mode detected (stdin is not a TTY); interactive console input is disabled.");
}
// LibDeflate is not thread safe, so we need to create a new instance for each thread
var standard = Deflate.Standard;
AppDomain.CurrentDomain.ProcessExit += (_, _) => standard.Dispose();