Panel: unticking 'web panel enabled' + restart panel really turns it off (2.9.5)
The restart used to refuse when the panel was disabled, so it stayed reachable. Now it stops the panel (also the relay on the game port); 'panel on|off' in the console turns it on/off and saves server.json. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+46
-2
@@ -111,7 +111,9 @@ public sealed class ServerHost
|
||||
{
|
||||
bool portChanged = fresh.Port != listenerPort;
|
||||
Config = fresh;
|
||||
Panel?.RestartWeb(fresh);
|
||||
if (!fresh.PanelEnabled) { StopPanel(by); return; } // "Web-Panel an" abgehakt: wirklich ausschalten
|
||||
if (Panel == null) StartPanel();
|
||||
else Panel.RestartWeb(fresh);
|
||||
if (!portChanged) return;
|
||||
if (Server != null && State == HostState.Running) RequestRestart(by); // bindet beim Start den neuen Port
|
||||
else Listen(fresh.Port);
|
||||
@@ -132,6 +134,43 @@ public sealed class ServerHost
|
||||
RequestExit();
|
||||
}
|
||||
|
||||
/// <summary>Web-Panel ausschalten (Einstellung abgehakt + "Panel neu starten" oder Konsole "panel off").</summary>
|
||||
public void StopPanel(string by)
|
||||
{
|
||||
if (Panel == null) return;
|
||||
GameServer.Log($"Web panel turned off by {by} - turn it on again with 'panel on' in the console or PanelEnabled in server.json");
|
||||
var panel = Panel;
|
||||
Panel = null;
|
||||
if (Server != null) Server.Panel = null;
|
||||
try { panel.Stop(); } catch { }
|
||||
}
|
||||
|
||||
void StartPanel()
|
||||
{
|
||||
Panel = AdminPanel.Start(this, Config, dataDir);
|
||||
if (Server != null) Server.Panel = Panel;
|
||||
}
|
||||
|
||||
/// <summary>Konsole "panel on|off": Einstellung speichern und Panel starten bzw. stoppen.</summary>
|
||||
public string SetPanelEnabled(bool enabled, string by)
|
||||
{
|
||||
if (!offline)
|
||||
{
|
||||
try
|
||||
{
|
||||
var fresh = ServerConfig.LoadOrCreate(configPath, out _);
|
||||
fresh.PanelEnabled = enabled;
|
||||
fresh.Save(configPath);
|
||||
}
|
||||
catch (Exception e) { return "Could not save server.json: " + e.Message; }
|
||||
}
|
||||
Config.PanelEnabled = enabled;
|
||||
if (!enabled) { StopPanel(by); return "Web panel turned off"; }
|
||||
if (Panel == null) StartPanel();
|
||||
Panel?.PrintInfo();
|
||||
return "Web panel turned on";
|
||||
}
|
||||
|
||||
/// <summary>Ganzes Programm beenden (Strg+C, docker stop, "exit").</summary>
|
||||
public void RequestExit()
|
||||
{
|
||||
@@ -229,8 +268,13 @@ public sealed class ServerHost
|
||||
GameServer.Log("The server is not running ('exit' quits the program)");
|
||||
break;
|
||||
case "panel":
|
||||
if (Panel != null) Panel.PrintInfo(); else GameServer.Log("The web panel is disabled");
|
||||
{
|
||||
string arg = cmd.Split(' ').Length > 1 ? cmd.Split(' ')[1].ToLowerInvariant() : "";
|
||||
if (arg == "on" || arg == "off") GameServer.Log(SetPanelEnabled(arg == "on", "Console"));
|
||||
else if (Panel != null) Panel.PrintInfo();
|
||||
else GameServer.Log("The web panel is disabled - 'panel on' turns it on");
|
||||
break;
|
||||
}
|
||||
case "status":
|
||||
GameServer.Log($"Server {State.ToString().ToLower()}" + (LastError != null ? ": " + LastError : ""));
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user