using System.Globalization; using System.Text.Json; namespace FakeGameServer; internal static class FakeOutput { public static void Log(string category, string message) => Console.Out.WriteLine($"{Stamp()} [{category}] {message}"); // Mimics the real game's crash handling: print the error, write a crash log under // /Logs, and exit with a code that is 0 unless a test asks otherwise. public static int Crash(string dataPath, int exitCode, string message) { var text = $"{Stamp()}: Critical error occurred{Environment.NewLine}{message}"; Console.Out.WriteLine(text); var logDir = Path.Combine(dataPath, "Logs"); Directory.CreateDirectory(logDir); File.WriteAllText(Path.Combine(logDir, "server-crash.log"), text + Environment.NewLine); return exitCode; } private static string Stamp() => DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.InvariantCulture); } internal static class JsonOptions { public static readonly JsonSerializerOptions Indented = new() { WriteIndented = true }; }