Fixed redis server time functions.

Added kill option for servers with motd Finished in servermonitor
This commit is contained in:
Jonathan Williams 2014-10-11 04:40:53 -07:00
parent 9c8ed5360d
commit d3788e8ddc
6 changed files with 34 additions and 7 deletions

View File

@ -38,7 +38,7 @@ public class ServerStatusManager extends MiniPlugin
{
super("Server Status Manager", plugin);
_startUpDate = Utility.currentTimeMillis();
_startUpDate = Utility.currentTimeSeconds();
_lagMeter = lagMeter;
if (new File("IgnoreUpdates.dat").exists())

View File

@ -103,7 +103,7 @@ public class MinecraftServer
public boolean isJoinable()
{
if (_motd != null && (_motd.contains("Starting") || _motd.contains("Recruiting")
|| _motd.contains("Waiting") || _motd.contains("Cup") || _motd.isEmpty()))
|| _motd.contains("Waiting") || _motd.contains("Open in") || _motd.isEmpty()))
{
if (_playerCount < _maxPlayerCount)
{

View File

@ -325,7 +325,7 @@ public class RedisDataRepository<T extends Data> implements DataRepository<T>
protected Long currentTime()
{
return Utility.currentTimeMillis();
return Utility.currentTimeSeconds();
}
/**

View File

@ -151,7 +151,7 @@ public class RedisServerRepository implements ServerRepository
String serverName = serverData.getName();
String setKey = concatenate("serverstatus", "minecraft", _region.toString());
String dataKey = concatenate(setKey, serverName);
long expiry = Utility.currentTimeMillis() + timeout;
long expiry = Utility.currentTimeSeconds() + timeout;
Transaction transaction = jedis.multi();
transaction.set(dataKey, serializedData);
@ -308,7 +308,7 @@ public class RedisServerRepository implements ServerRepository
try
{
String min = "(" + Utility.currentTimeMillis();
String min = "(" + Utility.currentTimeSeconds();
String max = "+inf";
names = jedis.zrangeByScore(key, min, max);
}
@ -341,7 +341,7 @@ public class RedisServerRepository implements ServerRepository
try
{
String min = "-inf";
String max = Utility.currentTimeMillis() + "";
String max = Utility.currentTimeSeconds() + "";
names = jedis.zrangeByScore(key, min, max);
}
catch (JedisConnectionException exception)

View File

@ -59,6 +59,27 @@ public class Utility
return result;
}
/**
* @return the current timestamp (in seconds) fetched from the central jedis repository
* for synced timestamps.
*/
public static long currentTimeSeconds()
{
long currentTime = 0;
Jedis jedis = getPool().getResource();
try
{
currentTime = Long.parseLong(jedis.time().get(0));
}
finally
{
getPool().returnResource(jedis);
}
return currentTime;
}
/**
* @return the current timestamp (in milliseconds) fetched from the central jedis repository
* for synced timestamps.
@ -67,7 +88,7 @@ public class Utility
{
long currentTime = 0;
Jedis jedis = getPool().getResource();
try
{
currentTime = Long.parseLong(jedis.time().get(0));

View File

@ -92,6 +92,12 @@ public class ServerMonitor
for (MinecraftServer minecraftServer : serverStatuses)
{
if (minecraftServer.getMotd().contains("Finished"))
{
killServer(minecraftServer.getName(), minecraftServer.getPublicAddress(), "[KILLED] [FINISHED] " + minecraftServer.getName() + ":" + minecraftServer.getPublicAddress(), true);
continue;
}
for (DedicatedServer server : dedicatedServers)
{
if (serverGroupMap.containsKey(minecraftServer.getGroup()) && minecraftServer.getPublicAddress().equalsIgnoreCase(server.getPrivateAddress()))