Added HostName to server groups.

Added handling of private server groups in server monitor.
Optimized server group/server status load.
Added ability to add/remove server group.
This commit is contained in:
Jonathan Williams 2014-12-23 00:49:52 -05:00
parent b83a81ec7e
commit 0e85b7e6cc
9 changed files with 392 additions and 189 deletions

View File

@ -0,0 +1,76 @@
package mineplex.core.personalServer;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.serverdata.Region;
import mineplex.serverdata.ServerGroup;
import mineplex.serverdata.ServerManager;
import mineplex.serverdata.ServerRepository;
public class PersonalServerManager extends MiniPlugin
{
private ServerRepository _repository;
private boolean _us;
public PersonalServerManager(JavaPlugin plugin, CoreClientManager clientManager)
{
super("Personal Server Manager", plugin);
setupConfigValues();
_us = plugin.getConfig().getBoolean("serverstatus.us");
Region region = _us ? Region.US : Region.EU;
_repository = ServerManager.getServerRepository(region);
}
private void setupConfigValues()
{
try
{
GetPlugin().getConfig().addDefault("serverstatus.us", true);
GetPlugin().getConfig().set("serverstatus.us", GetPlugin().getConfig().getBoolean("serverstatus.us"));
GetPlugin().saveConfig();
}
catch (Exception e)
{
e.printStackTrace();
}
}
@EventHandler
public void testing(PlayerCommandPreprocessEvent event)
{
String[] parts = event.getMessage().split(" ");
String[] args = new String[parts.length - 1];
System.arraycopy(parts, 1, args, 0, parts.length - 1);
if (event.getMessage().toLowerCase().startsWith("/host"))
{
if (args == null || args.length == 0)
{
createGroup(event.getPlayer().getName(), event.getPlayer().getName(), 16, 16, "Smash");
}
}
}
private void createGroup(String host, String serverName, int minPlayers, int maxPlayers, String games)
{
final ServerGroup serverGroup = new ServerGroup(host, serverName, host, 1024, 1, 1, 0, 19999, true, "arcade.zip", "Arcade.jar", "plugins/Arcade/", minPlayers, maxPlayers,
true, false, false, games, "Player", false, false, true, false, true, true, false, false, false, false, true, true, true, false, false, "", _us ? Region.US : Region.EU);
GetPlugin().getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
public void run()
{
_repository.updateServerGroup(serverGroup);
}
});
}
}

View File

@ -23,7 +23,7 @@ public class ServerConfiguration extends MiniPlugin
Region region = plugin.getConfig().getBoolean("serverstatus.us") ? Region.US : Region.EU;
for (ServerGroup serverGroup : ServerManager.getServerRepository(region).getServerGroups(false))
for (ServerGroup serverGroup : ServerManager.getServerRepository(region).getServerGroups(null))
{
if (serverGroup.getName().equalsIgnoreCase(plugin.getConfig().getString("serverstatus.group")))
{

View File

@ -25,6 +25,7 @@ import mineplex.core.monitor.LagMeter;
import mineplex.core.movement.Movement;
import mineplex.core.npc.NpcManager;
import mineplex.core.packethandler.PacketHandler;
import mineplex.core.personalServer.PersonalServerManager;
import mineplex.core.pet.PetManager;
import mineplex.core.portal.Portal;
import mineplex.core.preferences.PreferencesManager;
@ -112,6 +113,7 @@ public class Hub extends JavaPlugin implements IRelation
new FileUpdater(this, portal);
new CustomTagFix(this, packetHandler);
//new Replay(this, packetHandler);
new PersonalServerManager(this, clientManager);
CombatManager combatManager = new CombatManager(this);

View File

@ -1,14 +1,7 @@
package mineplex.serverdata;
/**
* A MinecraftServer represents a snapshot of the internal
* state of an active Minecraft host server.
* @author Ty
*
*/
public class MinecraftServer
{
// The name of this server.
private String _name;
public String getName() { return _name; }

View File

@ -2,6 +2,7 @@ package mineplex.serverdata;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@ -260,7 +261,7 @@ public class RedisServerRepository implements ServerRepository
}
@Override
public Collection<ServerGroup> getServerGroups(boolean fetch)
public Collection<ServerGroup> getServerGroups(Collection<MinecraftServer> serverStatuses)
{
Collection<ServerGroup> servers = new HashSet<ServerGroup>();
Jedis jedis = _jedisPool.getResource();
@ -284,7 +285,10 @@ public class RedisServerRepository implements ServerRepository
for (Response<Map<String, String>> response : serverDatas)
{
Map<String, String> data = response.get();
servers.add(new ServerGroup(data, _region, fetch));
ServerGroup serverGroup = new ServerGroup(data, serverStatuses);
if (serverGroup.getRegion() == Region.ALL || serverGroup.getRegion() == _region)
servers.add(serverGroup);
}
}
catch (JedisConnectionException exception)
@ -426,6 +430,70 @@ public class RedisServerRepository implements ServerRepository
return servers;
}
@Override
public void updateServerGroup(ServerGroup serverGroup)
{
Jedis jedis = _jedisPool.getResource();
try
{
HashMap<String, String> serializedData = serverGroup.getDataMap();
System.out.println(serializedData);
String serverGroupName = serverGroup.getName();
String key = "servergroups";
String dataKey = concatenate(key, serverGroupName);
Transaction transaction = jedis.multi();
transaction.hmset(dataKey, serializedData);
transaction.sadd(key, serverGroupName);
transaction.exec();
}
catch (JedisConnectionException exception)
{
exception.printStackTrace();
_jedisPool.returnBrokenResource(jedis);
jedis = null;
}
finally
{
if (jedis != null)
{
_jedisPool.returnResource(jedis);
}
}
}
@Override
public void removeServerGroup(ServerGroup serverGroup)
{
Jedis jedis = _jedisPool.getResource();
try
{
String serverName = serverGroup.getName();
String setKey = "servergroups";
String dataKey = concatenate(setKey, serverName);
Transaction transaction = jedis.multi();
transaction.del(dataKey);
transaction.srem(setKey, serverName);
transaction.exec();
}
catch (JedisConnectionException exception)
{
exception.printStackTrace();
_jedisPool.returnBrokenResource(jedis);
jedis = null;
}
finally
{
if (jedis != null)
{
_jedisPool.returnResource(jedis);
}
}
}
/*
* <region> = "US" or "EU"

View File

@ -1,147 +1,67 @@
package mineplex.serverdata;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* A ServerGroup represents a set of associated requirements for a type of {@link MinecraftServer}.
* @author Ty
*
*/
public class ServerGroup
{
// The unique name identifying this ServerGroup.
private HashMap<String, String> _dataMap = null;
private String _name;
public String getName() { return _name; }
// The prefix used to desginate this type of ServerGroup.
private String _host;
private String _prefix;
public String getPrefix() { return _prefix; }
// The name of the shell script used to start the minecraft server instance.
private String _scriptName;
public String getScriptName() { return _scriptName; }
// The amount of ram required for a server instance of this group type
private int _requiredRam;
public int getRequiredRam() { return _requiredRam; }
// The amount of cpu required for a server instance of this group type
private int _requiredCpu;
public int getRequiredCpu() { return _requiredCpu; }
// The total amount of servers required to be active of this group type
private int _requiredTotalServers;
public int getRequiredTotalServers() { return _requiredTotalServers; }
// The amount of joinable (non-full) servers required to be active for this group
private int _requiredJoinableServers;
public int getRequiredJoinableServers() { return _requiredJoinableServers; }
private int _portSection;
public int getPortSection() { return _portSection; }
private boolean _arcadeGroup;
public boolean getArcadeGroup() { return _arcadeGroup; }
private String _worldZip;
public String getWorldZip() { return _worldZip; }
private String _plugin;
public String getPlugin() { return _plugin; }
private String _configPath;
public String getConfigPath() { return _configPath; }
private int _minPlayers;
public int getMinPlayers() { return _minPlayers; }
private int _maxPlayers;
public int getMaxPlayers() { return _maxPlayers; }
private int _requiredRam;
private int _requiredCpu;
private int _requiredTotalServers;
private int _requiredJoinableServers;
private boolean _arcadeGroup;
private String _worldZip;
private String _plugin;
private String _configPath;
private int _portSection;
private boolean _pvp;
public boolean getPvp() { return _pvp; }
private boolean _tournament;
public boolean getTournament() { return _tournament; }
private boolean _tournamentPoints;
public boolean getTournamentPoints() { return _tournamentPoints; }
private boolean _teamRejoin;
public boolean getTeamRejoin() { return _teamRejoin; }
private boolean _teamAutoJoin;
public boolean getTeamAutoJoin() { return _teamAutoJoin; }
private boolean _teamForceBalance;
public boolean getTeamForceBalance() { return _teamForceBalance; }
private boolean _gameAutoStart;
public boolean getGameAutoStart() { return _gameAutoStart; }
private boolean _gameTimeout;
public boolean getGameTimeout() { return _gameTimeout; }
private boolean _rewardGems;
public boolean getRewardGems() { return _rewardGems; }
private boolean _rewardItems;
public boolean getRewardItems() { return _rewardItems; }
private boolean _rewardStats;
public boolean getRewardStats() { return _rewardStats; }
private boolean _rewardAchievements;
public boolean getRewardAchievements() { return _rewardAchievements; }
private boolean _hotbarInventory;
public boolean getHotbarInventory() { return _hotbarInventory; }
private boolean _hotbarHubClock;
public boolean getHotbarHubClock() { return _hotbarHubClock; }
private boolean _playerKickIdle;
public boolean getPlayerKickIdle() { return _playerKickIdle; }
private boolean _generateFreeVersions;
public boolean getGenerateFreeVersions() { return _generateFreeVersions; }
private String _games;
public String getGames() { return _games; }
private String _serverType;
public String getServerType() { return _serverType; }
private String _serverType;
private boolean _addNoCheat;
public boolean getAddNoCheat() { return _addNoCheat; }
private boolean _whitelist;
public boolean getWhitelist() { return _whitelist; }
private boolean _staffOnly;
public boolean getStaffOnly() { return _staffOnly; }
private String _resourcePack = "";
public String getResourcePack() { return _resourcePack; }
// The set of active MinecraftServers that belong to this server group
private Set<MinecraftServer> _servers;
public Set<MinecraftServer> getServers() { return _servers; }
/**
* Class constructor
* @param data - the set of serialized data values representing
* the internal state of this ServerGroup.
* @param region - the region from which to fetch active {@link MinecraftServer}s.
*/
public ServerGroup(Map<String, String> data, Region region, boolean fetch)
private Region _region;
private Set<MinecraftServer> _servers;
public ServerGroup(Map<String, String> data, Collection<MinecraftServer> serverStatuses)
{
_name = data.get("name");
_prefix = data.get("prefix");
_scriptName = data.get("scriptName");
_requiredRam = Integer.valueOf(data.get("ram"));
_requiredCpu = Integer.valueOf(data.get("cpu"));
_requiredTotalServers = Integer.valueOf(data.get("totalServers"));
@ -175,24 +95,108 @@ public class ServerGroup
_staffOnly = Boolean.valueOf(data.get("staffOnly"));
_whitelist = Boolean.valueOf(data.get("whitelist"));
_resourcePack = data.containsKey("resourcePack") ? data.get("resourcePack") : "";
_host = data.get("host");
_region = data.containsKey("region") ? Region.valueOf(data.get("region")) : Region.ALL;
if (fetch)
fetchServers(region);
if (serverStatuses != null)
parseServers(serverStatuses);
}
/**
* @return the total number of currently active {@link MinecraftServer}s belonging
* to this server group.
*/
public ServerGroup(String name, String prefix, String host, int ram, int cpu, int totalServers, int joinable, int portSection, boolean arcade, String worldZip, String plugin, String configPath
, int minPlayers, int maxPlayers, boolean pvp, boolean tournament, boolean tournamentPoints, String games, String serverType, boolean noCheat, boolean teamRejoin
, boolean teamAutoJoin, boolean teamForceBalance, boolean gameAutoStart, boolean gameTimeout, boolean rewardGems, boolean rewardItems, boolean rewardStats
, boolean rewardAchievements, boolean hotbarInventory, boolean hotbarHubClock, boolean playerKickIdle, boolean staffOnly, boolean whitelist, String resourcePack, Region region)
{
_name = name;
_prefix = prefix;
_host = host;
_requiredRam = ram;
_requiredCpu = cpu;
_requiredTotalServers = totalServers;
_requiredJoinableServers = joinable;
_portSection = portSection;
_arcadeGroup = arcade;
_worldZip = worldZip;
_plugin = plugin;
_configPath = configPath;
_minPlayers = minPlayers;
_maxPlayers = maxPlayers;
_pvp = pvp;
_tournament = tournament;
_tournamentPoints = tournamentPoints;
_games = games;
_serverType = serverType;
_addNoCheat = noCheat;
_teamRejoin = teamRejoin;
_teamAutoJoin = teamAutoJoin;
_teamForceBalance = teamForceBalance;
_gameAutoStart = gameAutoStart;
_gameTimeout = gameTimeout;
_rewardGems = rewardGems;
_rewardItems = rewardItems;
_rewardStats = rewardStats;
_rewardAchievements = rewardAchievements;
_hotbarInventory = hotbarInventory;
_hotbarHubClock = hotbarHubClock;
_playerKickIdle = playerKickIdle;
_staffOnly = staffOnly;
_whitelist = whitelist;
_resourcePack = resourcePack;
_region = region;
}
public String getName() { return _name; }
public String getHost() { return _host; }
public String getPrefix() { return _prefix; }
public int getMinPlayers() { return _minPlayers; }
public int getMaxPlayers() { return _maxPlayers; }
public int getRequiredRam() { return _requiredRam; }
public int getRequiredCpu() { return _requiredCpu; }
public int getRequiredTotalServers() { return _requiredTotalServers; }
public int getRequiredJoinableServers() { return _requiredJoinableServers; }
public int getPortSection() { return _portSection; }
public boolean getArcadeGroup() { return _arcadeGroup; }
public String getWorldZip() { return _worldZip; }
public String getPlugin() { return _plugin; }
public String getConfigPath() { return _configPath; }
public boolean getPvp() { return _pvp; }
public boolean getTournament() { return _tournament; }
public boolean getTournamentPoints() { return _tournamentPoints; }
public boolean getTeamRejoin() { return _teamRejoin; }
public boolean getTeamAutoJoin() { return _teamAutoJoin; }
public boolean getTeamForceBalance() { return _teamForceBalance; }
public boolean getGameAutoStart() { return _gameAutoStart; }
public boolean getGameTimeout() { return _gameTimeout; }
public boolean getRewardGems() { return _rewardGems; }
public boolean getRewardItems() { return _rewardItems; }
public boolean getRewardStats() { return _rewardStats; }
public boolean getRewardAchievements() { return _rewardAchievements; }
public boolean getHotbarInventory() { return _hotbarInventory; }
public boolean getHotbarHubClock() { return _hotbarHubClock; }
public boolean getPlayerKickIdle() { return _playerKickIdle; }
public boolean getGenerateFreeVersions() { return _generateFreeVersions; }
public String getGames() { return _games; }
public String getServerType() { return _serverType; }
public boolean getAddNoCheat() { return _addNoCheat; }
public boolean getWhitelist() { return _whitelist; }
public boolean getStaffOnly() { return _staffOnly; }
public String getResourcePack() { return _resourcePack; }
public Region getRegion() { return _region; }
public Set<MinecraftServer> getServers() { return _servers; }
public int getServerCount()
{
return _servers.size();
}
/**
* @return the total number of currently joinable (non-full) {@link MinecraftServer}s
* belonging to this server group.
*/
public int getJoinableCount()
{
int joinable = 0;
@ -208,10 +212,6 @@ public class ServerGroup
return joinable;
}
/**
* @return the total player count across all {@link MinecraftServer}s
* belonging to this server group.
*/
public int getPlayerCount()
{
int playerCount = 0;
@ -224,10 +224,6 @@ public class ServerGroup
return playerCount;
}
/**
* @return the total maximum player count across all {@link MinecraftServer}s
* belonging to this server group.
*/
public int getMaxPlayerCount()
{
int maxPlayerCount = 0;
@ -240,10 +236,6 @@ public class ServerGroup
return maxPlayerCount;
}
/**
* @return a {@link Collection} of active but empty {@link MinecraftServer}s that belong
* to this server group.
*/
public Collection<MinecraftServer> getEmptyServers()
{
Collection<MinecraftServer> emptyServers = new HashSet<MinecraftServer>();
@ -259,16 +251,11 @@ public class ServerGroup
return emptyServers;
}
/**
* Update & fetch all {@link MinecraftServer}s that belong to this server group and
* store them in {@code servers} field.
*/
private void fetchServers(Region region)
private void parseServers(Collection<MinecraftServer> servers)
{
this._servers = new HashSet<MinecraftServer>();
ServerRepository repository = ServerManager.getServerRepository(region);
for (MinecraftServer server : repository.getServerStatuses())
_servers = new HashSet<MinecraftServer>();
for (MinecraftServer server : servers)
{
if (_name.equalsIgnoreCase(server.getGroup()))
{
@ -277,9 +264,6 @@ public class ServerGroup
}
}
/**
* @return a unique server name suffix id, unique to any servers in this ServerGroup.
*/
public int generateUniqueId(int startId)
{
int id = startId;
@ -317,4 +301,51 @@ public class ServerGroup
}
}
}
public HashMap<String, String> getDataMap()
{
if (_dataMap == null)
{
_dataMap = new HashMap<String, String>();
_dataMap.put("name", _name);
_dataMap.put("prefix", _prefix);
_dataMap.put("ram", _requiredRam + "");
_dataMap.put("cpu", _requiredCpu + "");
_dataMap.put("totalServers", _requiredTotalServers + "");
_dataMap.put("joinableServers", _requiredJoinableServers + "");
_dataMap.put("portSection", _portSection + "");
_dataMap.put("arcadeGroup", _arcadeGroup + "");
_dataMap.put("worldZip", _worldZip);
_dataMap.put("plugin", _plugin);
_dataMap.put("configPath", _configPath);
_dataMap.put("minPlayers", _minPlayers + "");
_dataMap.put("maxPlayers", _maxPlayers + "");
_dataMap.put("pvp", _pvp + "");
_dataMap.put("tournament", _tournament + "");
_dataMap.put("tournamentPoints", _tournamentPoints + "");
_dataMap.put("games", _games);
_dataMap.put("serverType", _serverType);
_dataMap.put("addNoCheat", _addNoCheat + "");
_dataMap.put("teamRejoin", _teamRejoin + "");
_dataMap.put("teamAutoJoin", _teamAutoJoin + "");
_dataMap.put("teamForceBalance", _teamForceBalance + "");
_dataMap.put("gameAutoStart", _gameAutoStart + "");
_dataMap.put("gameTimeout", _gameTimeout + "");
_dataMap.put("rewardGems", _rewardGems + "");
_dataMap.put("rewardItems", _rewardItems + "");
_dataMap.put("rewardStats", _rewardStats + "");
_dataMap.put("rewardAchievements", _rewardAchievements + "");
_dataMap.put("hotbarInventory", _hotbarInventory + "");
_dataMap.put("hotbarHubClock", _hotbarHubClock + "");
_dataMap.put("playerKickIdle", _playerKickIdle + "");
_dataMap.put("staffOnly", _staffOnly + "");
_dataMap.put("whitelist", _whitelist + "");
_dataMap.put("resourcePack", _resourcePack);
_dataMap.put("host", _host);
_dataMap.put("region", _region.name());
}
return _dataMap;
}
}

View File

@ -61,8 +61,12 @@ public interface ServerRepository
* @return a newly instanced snapshot {@link Collection} of all the
* currently active {@link ServerGroup}s in the repository.
*/
public Collection<ServerGroup> getServerGroups(boolean fetch);
public Collection<ServerGroup> getServerGroups(Collection<MinecraftServer> servers);
public Collection<MinecraftServer> getDeadServers();
void updateServerGroup(ServerGroup serverGroup);
public void removeServerGroup(ServerGroup serverGroup);
}

View File

@ -35,6 +35,10 @@ public class ServerMonitor
private static int _count = 0;
private static HashSet<ProcessRunner> _processes = new HashSet<ProcessRunner>();
private static HashMap<String, Boolean> _badServers = new HashMap<String, Boolean>();
private static Collection<MinecraftServer> _serverStatuses = null;
private static Collection<ServerGroup> _serverGroups = null;
private static Map<String, ServerGroup> _serverGroupMap = null;
private static List<DedicatedServer> _dedicatedServers = null;
private static SimpleDateFormat _dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
private static Logger _logger = Logger.getLogger("ServerMonitor");
@ -65,7 +69,7 @@ public class ServerMonitor
try
{
FileHandler fileHandler = new FileHandler("monitor.log");
FileHandler fileHandler = new FileHandler("monitor.log", true);
fileHandler.setFormatter(new CustomFormatter());
_logger.addHandler(fileHandler);
_logger.setUseParentHandlers(false);
@ -80,38 +84,29 @@ public class ServerMonitor
while (true)
{
_totalPlayers = 0;
Collection<ServerGroup> serverGroups = _repository.getServerGroups(true);
Collection<MinecraftServer> serverStatuses = _repository.getServerStatuses();
for (MinecraftServer deadServer : _repository.getDeadServers())
{
killServer(deadServer.getName(), deadServer.getPublicAddress(), "[KILLED] [DEAD] " + deadServer.getName() + ":" + deadServer.getPublicAddress(), true);
}
_serverStatuses = _repository.getServerStatuses();
_serverGroups = _repository.getServerGroups(_serverStatuses);
_serverGroupMap = new HashMap<String, ServerGroup>();
_dedicatedServers = new ArrayList<DedicatedServer>(_repository.getDedicatedServers());
List<DedicatedServer> dedicatedServers = new ArrayList<DedicatedServer>(_repository.getDedicatedServers());
calculateTotalPlayers();
killDeadServers();
Map<String, ServerGroup> serverGroupMap = new HashMap<String, ServerGroup>();
for (ServerGroup serverGroup : serverGroups)
{
serverGroupMap.put(serverGroup.getName(), serverGroup);
_totalPlayers += serverGroup.getPlayerCount();
}
System.out.println("Total Players : " + _totalPlayers);
for (MinecraftServer minecraftServer : serverStatuses)
for (MinecraftServer minecraftServer : _serverStatuses)
{
if (minecraftServer.getMotd().contains("Finished") || (minecraftServer.getGroup().equalsIgnoreCase("UltraHardcore") && minecraftServer.getMotd().contains("Restarting") && minecraftServer.getPlayerCount() == 0))
{
killServer(minecraftServer.getName(), minecraftServer.getPublicAddress(), "[KILLED] [FINISHED] " + minecraftServer.getName() + ":" + minecraftServer.getPublicAddress(), true);
handleUserServerGroup(_serverGroupMap.get(minecraftServer.getGroup()));
continue;
}
for (DedicatedServer server : dedicatedServers)
for (DedicatedServer server : _dedicatedServers)
{
if (serverGroupMap.containsKey(minecraftServer.getGroup()) && minecraftServer.getPublicAddress().equalsIgnoreCase(server.getPrivateAddress()))
if (_serverGroupMap.containsKey(minecraftServer.getGroup()) && minecraftServer.getPublicAddress().equalsIgnoreCase(server.getPrivateAddress()))
{
ServerGroup serverGroup = serverGroupMap.get(minecraftServer.getGroup());
ServerGroup serverGroup = _serverGroupMap.get(minecraftServer.getGroup());
server.incrementServerCount(serverGroup);
}
}
@ -121,7 +116,7 @@ public class ServerMonitor
{
_badServers.clear();
for (DedicatedServer serverData : dedicatedServers)
for (DedicatedServer serverData : _dedicatedServers)
{
if (isServerOffline(serverData))
{
@ -133,7 +128,7 @@ public class ServerMonitor
log(_badServers.size() + " bad servers.");
}
for (Iterator<DedicatedServer> iterator = dedicatedServers.iterator(); iterator.hasNext();)
for (Iterator<DedicatedServer> iterator = _dedicatedServers.iterator(); iterator.hasNext();)
{
DedicatedServer serverData = iterator.next();
@ -141,30 +136,30 @@ public class ServerMonitor
iterator.remove();
}
for (ServerGroup groupStatus : serverGroups)
for (ServerGroup groupStatus : _serverGroups)
{
NautHashMap<Integer, MinecraftServer> _serverMap = new NautHashMap<Integer, MinecraftServer>();
NautHashMap<Integer, MinecraftServer> serverMap = new NautHashMap<Integer, MinecraftServer>();
for (Iterator<MinecraftServer> serverIterator = groupStatus.getServers().iterator(); serverIterator.hasNext();)
{
MinecraftServer server = serverIterator.next();
int serverNum = Integer.parseInt(server.getName().split("-")[1]);
if (_serverMap.containsKey(serverNum))
if (serverMap.containsKey(serverNum))
{
killServer(server.getName(), server.getPublicAddress(), "[KILLED] [DUPLICATE] " + server.getName() + ":" + server.getPublicAddress(), true);
serverIterator.remove();
}
else
{
_serverMap.put(serverNum, server);
serverMap.put(serverNum, server);
}
}
}
HashSet<String> onlineServers = new HashSet<String>();
for (MinecraftServer minecraftServer : serverStatuses)
for (MinecraftServer minecraftServer : _serverStatuses)
{
onlineServers.add(minecraftServer.getName());
@ -187,12 +182,12 @@ public class ServerMonitor
}
}
for (ServerGroup serverGroup : serverGroups)
for (ServerGroup serverGroup : _serverGroups)
{
if (serverGroup.getName().equals("Testing"))
continue;
handleGroupChanges(dedicatedServers, serverTracker, serverGroup, false);
handleGroupChanges(serverTracker, serverGroup, false);
}
int processWaits = 0;
@ -259,7 +254,39 @@ public class ServerMonitor
}
}
private static void handleGroupChanges(List<DedicatedServer> dedicatedServers, HashMap<String, Entry<String, Long>> serverTracker, ServerGroup serverGroup, boolean free)
private static void killDeadServers()
{
for (MinecraftServer deadServer : _repository.getDeadServers())
{
killServer(deadServer.getName(), deadServer.getPublicAddress(), "[KILLED] [DEAD] " + deadServer.getName() + ":" + deadServer.getPublicAddress(), true);
handleUserServerGroup(_serverGroupMap.get(deadServer.getGroup()));
}
}
private static void handleUserServerGroup(ServerGroup serverGroup)
{
if (serverGroup != null && serverGroup.getHost() != null && !serverGroup.getHost().isEmpty() && serverGroup.getServerCount() == 0)
{
_repository.removeServerGroup(serverGroup);
_serverGroupMap.remove(serverGroup);
_serverGroups.remove(serverGroup);
System.out.println("Removed ServerGroup : " + serverGroup.getName());
}
}
private static void calculateTotalPlayers()
{
for (ServerGroup serverGroup : _serverGroups)
{
_serverGroupMap.put(serverGroup.getName(), serverGroup);
_totalPlayers += serverGroup.getPlayerCount();
}
System.out.println("Total Players : " + _totalPlayers);
}
private static void handleGroupChanges(HashMap<String, Entry<String, Long>> serverTracker, ServerGroup serverGroup, boolean free)
{
int serverNum = 0;
int requiredTotal = serverGroup.getRequiredTotalServers();
@ -307,11 +334,20 @@ public class ServerMonitor
serversToKill = maxUHC - joinableServers;
}
// KILL, CLEAN, THEN ADD
while (serversToKill > 0)
{
List<MinecraftServer> emptyServers = new ArrayList<MinecraftServer>(serverGroup.getEmptyServers());
MinecraftServer emptyServer = emptyServers.get(serversToKill - 1);
killServer(emptyServer, "[KILLED] [EXCESS] " + emptyServer.getName() + ":" + emptyServer.getPublicAddress());
serversToKill--;
}
while (serversToAdd > 0)
{
serverNum = serverGroup.generateUniqueId(serverNum + 1);
Collections.sort(dedicatedServers, new DedicatedServerSorter());
DedicatedServer bestServer = getBestDedicatedServer(dedicatedServers, serverGroup);
Collections.sort(_dedicatedServers, new DedicatedServerSorter());
DedicatedServer bestServer = getBestDedicatedServer(_dedicatedServers, serverGroup);
if (bestServer == null)
{
@ -329,14 +365,6 @@ public class ServerMonitor
serversToAdd--;
}
while (serversToKill > 0)
{
List<MinecraftServer> emptyServers = new ArrayList<MinecraftServer>(serverGroup.getEmptyServers());
MinecraftServer emptyServer = emptyServers.get(serversToKill - 1);
killServer(emptyServer, "[KILLED] [EXCESS] " + emptyServer.getName() + ":" + emptyServer.getPublicAddress());
serversToKill--;
}
}
private static void killServer(final String serverName, final String serverAddress, final String message, final boolean announce)

View File

@ -149,6 +149,7 @@ public class Arcade extends JavaPlugin
try
{
config.HostName = _serverConfiguration.getServerGroup().getHost();
config.ServerType = _serverConfiguration.getServerGroup().getServerType();
config.MinPlayers = _serverConfiguration.getServerGroup().getMinPlayers();
config.MaxPlayers = _serverConfiguration.getServerGroup().getMaxPlayers();