From e29dd4ff71f36844f632ec729067e92d687cd9d9 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Thu, 25 Sep 2014 05:37:10 -0700 Subject: [PATCH] Fixes for ServerMonitor. --- .../serverdata/RedisServerRepository.java | 26 ++++-------------- .../mineplex/servermonitor/ServerMonitor.java | 27 +++++++++++++++++-- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java index 25c50dd56..8f3ae9073 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java @@ -185,7 +185,7 @@ public class RedisServerRepository implements ServerRepository String dataKey = concatenate(setKey, serverName); Transaction transaction = jedis.multi(); - transaction.set(dataKey, null); + transaction.del(dataKey); transaction.zrem(setKey, serverName); transaction.exec(); } @@ -258,25 +258,6 @@ public class RedisServerRepository implements ServerRepository } } - Map serverGroups = new HashMap(); - for (ServerGroup serverGroup : getServerGroups()) - { - serverGroups.put(serverGroup.getName(), serverGroup); - } - - // TODO: Find cleaner way to prep dedicated server group counts? - for (DedicatedServer server : servers) - { - for (MinecraftServer minecraftServer : getServerStatuses()) - { - if (serverGroups.containsKey(minecraftServer.getGroup())) - { - ServerGroup serverGroup = serverGroups.get(minecraftServer.getGroup()); - server.incrementServerCount(serverGroup); - } - } - } - return servers; } @@ -415,7 +396,10 @@ public class RedisServerRepository implements ServerRepository for (Response response : responses) { String serializedData = response.get(); - servers.add(Utility.deserialize(serializedData, MinecraftServer.class)); + MinecraftServer server = Utility.deserialize(serializedData, MinecraftServer.class); + + if (server != null) + servers.add(server); } } catch (JedisConnectionException exception) diff --git a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java index d271edc74..b01f2a25d 100644 --- a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java +++ b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java @@ -14,6 +14,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Map.Entry; import java.util.logging.FileHandler; import java.util.logging.Logger; @@ -74,7 +75,8 @@ public class ServerMonitor while (true) { Collection serverGroups = _repository.getServerGroups(); - + Collection serverStatuses = _repository.getServerStatuses(); + for (MinecraftServer deadServer : _repository.getDeadServers()) { killServer(deadServer.getName(), deadServer.getPublicAddress(), "[KILLED] [DEAD] " + deadServer.getName() + ":" + deadServer.getPublicAddress(), true); @@ -82,6 +84,24 @@ public class ServerMonitor List dedicatedServers = new ArrayList(_repository.getDedicatedServers()); + Map serverGroupMap = new HashMap(); + for (ServerGroup serverGroup : serverGroups) + { + serverGroupMap.put(serverGroup.getName(), serverGroup); + } + + for (MinecraftServer minecraftServer : serverStatuses) + { + for (DedicatedServer server : dedicatedServers) + { + if (serverGroupMap.containsKey(minecraftServer.getGroup()) && minecraftServer.getPublicAddress().equalsIgnoreCase(server.getPrivateAddress())) + { + ServerGroup serverGroup = serverGroupMap.get(minecraftServer.getGroup()); + server.incrementServerCount(serverGroup); + } + } + } + if (_count % 15 == 0) { _badServers.clear(); @@ -129,7 +149,7 @@ public class ServerMonitor HashSet onlineServers = new HashSet(); - for (MinecraftServer minecraftServer : _repository.getServerStatuses()) + for (MinecraftServer minecraftServer : serverStatuses) { onlineServers.add(minecraftServer.getName()); @@ -237,7 +257,10 @@ public class ServerMonitor int availableSlots = serverGroup.getMaxPlayerCount() - serverGroup.getPlayerCount(); if (availableSlots < 1500) + { serversToAdd = Math.max(1, (1500 - availableSlots) / serverGroup.getMaxPlayers()); + serversToKill = 0; + } else if (serversToKill > 0) serversToKill = Math.min(serversToKill, (availableSlots - 1500) / 80); }