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