diff --git a/server/Commands/RunCommand.cs b/server/Commands/RunCommand.cs index c4f6e45..b2099b2 100644 --- a/server/Commands/RunCommand.cs +++ b/server/Commands/RunCommand.cs @@ -707,6 +707,49 @@ public sealed class RunCommand : AsyncCommand return Results.Json(new { ok = true, restartRequired = serverProc.IsRunning }); }); + // ── Daemon config (safe subset of server-config.json) ── + // Lets the panel edit things that live in our own config, not server.properties: + // memoryMB (the JVM -Xmx). Sensitive fields (passwords, manifestUrl, ports) are + // intentionally not exposed here -- those still need direct file edits + restart. + app.MapGet("/api/daemon/config", () => Results.Json(new + { + memoryMB = config.MemoryMB, + })); + + app.MapPost("/api/daemon/config", async (HttpContext ctx) => + { + using var sr = new StreamReader(ctx.Request.Body); + var payload = JsonSerializer.Deserialize>( + await sr.ReadToEndAsync(), JsonOpts.CaseInsensitive); + if (payload is null || payload.Count == 0) + return Results.BadRequest(new { ok = false, error = "Empty payload." }); + + var changed = false; + + if (payload.TryGetValue("memoryMB", out var memEl)) + { + int memMB; + if (memEl.ValueKind == JsonValueKind.Number) memMB = memEl.GetInt32(); + else if (!int.TryParse(memEl.GetString(), out memMB)) + return Results.BadRequest(new { ok = false, error = "memoryMB must be a number" }); + + // Sanity bounds. MC needs at least 1 GB; absolute cap of 64 GB protects against + // a fat-fingered entry that would refuse to start (JVM allocates Xmx up front). + if (memMB < 1024) return Results.BadRequest(new { ok = false, error = "memoryMB must be >= 1024" }); + if (memMB > 65536) return Results.BadRequest(new { ok = false, error = "memoryMB must be <= 65536" }); + + if (config.MemoryMB != memMB) + { + config.MemoryMB = memMB; + changed = true; + } + } + + if (changed) config.Save(configPath); + // Memory changes always require a restart -- the JVM can't grow -Xmx at runtime. + return Results.Json(new { ok = true, restartRequired = changed && serverProc.IsRunning }); + }); + // ── BlueMap (manual render) ── app.MapGet("/api/map/status", () => Results.Json(new { diff --git a/server/wwwroot/index.html b/server/wwwroot/index.html index 9f8d1b5..d49b1aa 100644 --- a/server/wwwroot/index.html +++ b/server/wwwroot/index.html @@ -263,8 +263,15 @@

- These map to server.properties. MC reads them at startup, so changes need a server restart to take effect. + These map to server.properties and the daemon config. MC reads them at startup, so changes need a server restart to take effect.

+ + +
+ +
+ +