Fixed agent auto-shutting down servers.

This commit is contained in:
Andrew Lalis 2024-08-10 14:29:27 -04:00
parent cf13456e18
commit 6c7688e80a
2 changed files with 18 additions and 13 deletions

View File

@ -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);
}
}

View File

@ -21,6 +21,7 @@ ServerStatus determineStatus(in ServerMetaData server) {
int playersOnline = 0;
string[] playerNames;
if (online) {
try {
MCRconResponse response = executeRconCommand(server, "list");
string playersList;
int tmp;
@ -33,6 +34,9 @@ ServerStatus determineStatus(in ServerMetaData server) {
.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,