Server 2.10.1: remote management from the MSCO Launcher
- Polls the keymaster every 5 s for commands from the owner's launcher, runs only allowed commands (say, kick, ban, save, backup, restart, mods reload, status, players), sends results and the player list back - RemoteManagement in server.json / web panel settings (on by default) to turn it off Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -59,6 +59,25 @@ public sealed class MasterClient
|
||||
public sealed record HeartbeatResult(int Status, bool? Reachable, bool Listed, string Address, int Port);
|
||||
record HeartbeatReply(bool? Reachable, bool Listed, string Address, int Port);
|
||||
|
||||
public sealed record RemoteCommand(string Id, string Command, string By);
|
||||
public sealed record RemoteResult(string Id, string Output);
|
||||
public sealed record RemotePlayer(int Id, string Name);
|
||||
record PollReply(List<RemoteCommand> Commands);
|
||||
|
||||
/// <summary>Befehle aus dem Launcher abholen (und Ergebnisse der letzten Befehle abliefern). null = Master nicht erreichbar.</summary>
|
||||
public async Task<List<RemoteCommand>> PollAsync(string key, List<RemoteResult> results, List<RemotePlayer> players)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(8));
|
||||
var response = await http.PostAsJsonAsync(baseUrl + "/api/servers/poll", new { key, results, players }, cts.Token);
|
||||
if (!response.IsSuccessStatusCode) return null;
|
||||
var reply = await response.Content.ReadFromJsonAsync<PollReply>(cancellationToken: cts.Token);
|
||||
return reply?.Commands ?? new List<RemoteCommand>();
|
||||
}
|
||||
catch { return null; }
|
||||
}
|
||||
|
||||
/// <summary>Beim Beenden: sofort aus der Serverliste nehmen (sonst erst nach dem Heartbeat-Timeout).</summary>
|
||||
public async Task UnregisterAsync(string key)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user