Fixed agent auto-shutting down servers.
This commit is contained in:
parent
cf13456e18
commit
6c7688e80a
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue