Cross-platform C# GUI to replace the Qt/C++ Host GUI, on the same dotnet toolchain as the server. MVP: load/save commonwealth-server.json, Start/Stop the CommonwealthOnline.Server process (published exe, then dll, then source run), and stream its output to a live log. Themed to the Commonwealth Online brand (near-black + amber). Builds clean on net8.0. Next: player list + kick/ban via the admin port, then retire the Qt host.
50 lines
1.6 KiB
C#
50 lines
1.6 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace CommonwealthOnline.Host.Services;
|
|
|
|
// Mirrors CommonwealthOnline.Server Configuration. Keep the JSON shape aligned
|
|
// with the server's own serializer so a config saved here loads there.
|
|
public sealed class ServerConfig
|
|
{
|
|
public string Host { get; set; } = "0.0.0.0";
|
|
public int Port { get; set; } = 7777;
|
|
public string ServerName { get; set; } = "Commonwealth Online Server";
|
|
public string ServerDescription { get; set; } = string.Empty;
|
|
public int MaxPlayers { get; set; } = 16;
|
|
public string LogVerbosity { get; set; } = "info";
|
|
public int AdminPort { get; set; } = 7779;
|
|
public bool EnableGnsTransport { get; set; }
|
|
public string? GnsBridgePath { get; set; }
|
|
|
|
private static readonly JsonSerializerOptions Options = new()
|
|
{
|
|
WriteIndented = true,
|
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
|
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
|
};
|
|
|
|
public static ServerConfig Load(string path)
|
|
{
|
|
try
|
|
{
|
|
if (File.Exists(path))
|
|
{
|
|
return JsonSerializer.Deserialize<ServerConfig>(File.ReadAllText(path), Options)
|
|
?? new ServerConfig();
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// Fall back to defaults on unreadable/invalid config.
|
|
}
|
|
|
|
return new ServerConfig();
|
|
}
|
|
|
|
public void Save(string path) =>
|
|
File.WriteAllText(path, JsonSerializer.Serialize(this, Options));
|
|
}
|