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) {
|
void checkForEmptyServers(ServerMetaData[] servers, ServerStatus[] statuses, AgentConfig config) {
|
||||||
foreach (i, server; servers) {
|
foreach (i, server; servers) {
|
||||||
ServerStatus status = statuses[i];
|
ServerStatus status = statuses[i];
|
||||||
if (status.online && status.playersOnline > 0) {
|
if (!status.online || (status.online && status.playersOnline > 0)) {
|
||||||
removeIdleTrackerFileIfPresent(server);
|
removeIdleTrackerFileIfPresent(server);
|
||||||
} else if (status.online && status.playersOnline == 0) {
|
} else if (status.online && status.playersOnline == 0) {
|
||||||
const Duration idleTime = getOrCreateIdleTrackerFileAndGetAge(server);
|
const Duration idleTime = getOrCreateIdleTrackerFileAndGetAge(server);
|
||||||
if (idleTime.total!"minutes" > config.serverInactivityTimeoutMinutes) {
|
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);
|
stopServer(server, config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,18 +21,22 @@ ServerStatus determineStatus(in ServerMetaData server) {
|
||||||
int playersOnline = 0;
|
int playersOnline = 0;
|
||||||
string[] playerNames;
|
string[] playerNames;
|
||||||
if (online) {
|
if (online) {
|
||||||
MCRconResponse response = executeRconCommand(server, "list");
|
try {
|
||||||
string playersList;
|
MCRconResponse response = executeRconCommand(server, "list");
|
||||||
int tmp;
|
string playersList;
|
||||||
response.text.formattedRead!"There are %d of a max of %d players online: %s"(
|
int tmp;
|
||||||
playersOnline,
|
response.text.formattedRead!"There are %d of a max of %d players online: %s"(
|
||||||
tmp,
|
playersOnline,
|
||||||
playersList
|
tmp,
|
||||||
);
|
playersList
|
||||||
playerNames = playersList.strip.split(",")
|
);
|
||||||
.filter!(s => s !is null && s.strip.length > 0)
|
playerNames = playersList.strip.split(",")
|
||||||
.map!(s => s.strip)
|
.filter!(s => s !is null && s.strip.length > 0)
|
||||||
.array;
|
.map!(s => s.strip)
|
||||||
|
.array;
|
||||||
|
} catch (Exception e) {
|
||||||
|
stderr.writefln!"Failed to get players from server: %s"(e.msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ServerStatus(
|
return ServerStatus(
|
||||||
server.name,
|
server.name,
|
||||||
|
|
Loading…
Reference in New Issue