From 6c7688e80a33e5c729ed10880fbb59804941b925 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Sat, 10 Aug 2024 14:29:27 -0400 Subject: [PATCH] Fixed agent auto-shutting down servers. --- agent/source/app.d | 3 ++- agent/source/server_actions.d | 28 ++++++++++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/agent/source/app.d b/agent/source/app.d index 94f504c..3265d08 100644 --- a/agent/source/app.d +++ b/agent/source/app.d @@ -68,11 +68,12 @@ void startRequestedServers(ServerMetaData[] servers, AgentConfig config) { void checkForEmptyServers(ServerMetaData[] servers, ServerStatus[] statuses, AgentConfig config) { foreach (i, server; servers) { ServerStatus status = statuses[i]; - if (status.online && status.playersOnline > 0) { + if (!status.online || (status.online && status.playersOnline > 0)) { removeIdleTrackerFileIfPresent(server); } else if (status.online && status.playersOnline == 0) { const Duration idleTime = getOrCreateIdleTrackerFileAndGetAge(server); if (idleTime.total!"minutes" > config.serverInactivityTimeoutMinutes) { + writefln!"Server %s has been idle for %d minutes, shutting down."(server.name, idleTime.total!"minutes"); stopServer(server, config); } } diff --git a/agent/source/server_actions.d b/agent/source/server_actions.d index 8e215a4..66a8293 100644 --- a/agent/source/server_actions.d +++ b/agent/source/server_actions.d @@ -21,18 +21,22 @@ ServerStatus determineStatus(in ServerMetaData server) { int playersOnline = 0; string[] playerNames; if (online) { - MCRconResponse response = executeRconCommand(server, "list"); - string playersList; - int tmp; - response.text.formattedRead!"There are %d of a max of %d players online: %s"( - playersOnline, - tmp, - playersList - ); - playerNames = playersList.strip.split(",") - .filter!(s => s !is null && s.strip.length > 0) - .map!(s => s.strip) - .array; + try { + MCRconResponse response = executeRconCommand(server, "list"); + string playersList; + int tmp; + response.text.formattedRead!"There are %d of a max of %d players online: %s"( + playersOnline, + tmp, + playersList + ); + playerNames = playersList.strip.split(",") + .filter!(s => s !is null && s.strip.length > 0) + .map!(s => s.strip) + .array; + } catch (Exception e) { + stderr.writefln!"Failed to get players from server: %s"(e.msg); + } } return ServerStatus( server.name,