Resolve merge conflicts.

This commit is contained in:
Ty 2014-08-04 19:14:04 -04:00
parent 1b7c762942
commit 2e43d565bd
6 changed files with 88 additions and 830 deletions

View File

@ -70,8 +70,6 @@ public class LobbyBalancer implements Listener, Runnable
// Since we had to enter our dangerzone, update local data so if we have to enter it again we don't pick the same server over and over
_sortedLobbies.get(_bestServerIndex).incrementPlayerCount(5);
sort = true;
}
}
@ -120,7 +118,7 @@ public class LobbyBalancer implements Listener, Runnable
if (_sortedLobbies.size() > 0)
_maxPlayersToSendToBestServer = (_sortedLobbies.get(_bestServerIndex).getMaxPlayerCount() - _sortedLobbies.get(_bestServerIndex).getPlayerCount()) / 10;
_maxPlayersToSendToBestServer = _sortedLobbies.get(_bestServerIndex).MaxPlayers - _sortedLobbies.get(_bestServerIndex).Players;
_maxPlayersToSendToBestServer = _sortedLobbies.get(_bestServerIndex).getMaxPlayerCount() - _sortedLobbies.get(_bestServerIndex).getPlayerCount();
long timeSpentInLock = System.currentTimeMillis() - startTime;

View File

@ -44,6 +44,45 @@ public class ServerGroup
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 _serverType; }
private String _plugin;
public String getPlugin() { return _serverType; }
private String _configPath;
public String getConfigPath() { return _serverType; }
private int _minPlayers;
public int getMinPlayers() { return _minPlayers; }
private int _maxPlayers;
public int getMaxPlayers() { return _maxPlayers; }
private boolean _pvp;
public boolean getPvp() { return _pvp; }
private boolean _tournament;
public boolean getTournament() { return _tournament; }
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 boolean _addNoCheat;
public boolean getAddNoCheat() { return _addNoCheat; }
// The set of active MinecraftServers that belong to this server group
private Set<MinecraftServer> servers;
@ -62,6 +101,19 @@ public class ServerGroup
this._requiredCpu = Integer.valueOf(data.get("cpu"));
this._requiredTotalServers = Integer.valueOf(data.get("totalServers"));
this._requiredJoinableServers = Integer.valueOf(data.get("joinableServers"));
this._portSection = Integer.valueOf(data.get("portSection"));
this._arcadeGroup = Boolean.valueOf(data.get("arcadeGroup"));
this._worldZip = data.get("worldZip");
this._plugin = data.get("plugin");
this._configPath = data.get("configPath");
this._minPlayers = Integer.valueOf(data.get("minPlayers"));
this._maxPlayers = Integer.valueOf(data.get("maxPlayers"));
this._pvp = Boolean.valueOf(data.get("pvp"));
this._tournament = Boolean.valueOf(data.get("tournament"));
this._generateFreeVersions = Boolean.valueOf(data.get("generateFreeVersions"));
this._games = data.get("games");
this._serverType = data.get("serverType");
this._addNoCheat = Boolean.valueOf(data.get("addNoCheat"));
fetchServers(region);
}

View File

@ -1,169 +0,0 @@
package mineplex.servermonitor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class GroupStatusData
{
private int _serverNum = 0;
private int _totalCount = 0;
private int _joinableCount = 0;
private int _freeServerNum = 0;
private int _freeTotalCount = 0;
private int _freeJoinableCount = 0;
public int Players;
public int MaxPlayers;
public List<ServerStatusData> EmptyServers = new ArrayList<ServerStatusData>();
public List<ServerStatusData> KillServers = new ArrayList<ServerStatusData>();
public HashMap<Integer, ServerStatusData> Servers = new HashMap<Integer, ServerStatusData>();
public HashMap<Integer, ServerStatusData> FreeServers = new HashMap<Integer, ServerStatusData>();
public void addServer(ServerStatusData serverStatusData)
{
boolean free = serverStatusData.Name.contains("FREE");
checkForDuplicate(free ? FreeServers : Servers, serverStatusData, free);
Players += serverStatusData.Players;
MaxPlayers += serverStatusData.MaxPlayers;
if (serverStatusData.Motd != null && (serverStatusData.Motd.contains("Starting") || serverStatusData.Motd.contains("Recruiting") || serverStatusData.Motd.contains("Waiting") || serverStatusData.Motd.contains("Cup") || serverStatusData.Motd.isEmpty() || serverStatusData.Motd.equals("")))
{
if (serverStatusData.Players < serverStatusData.MaxPlayers)
{
// Lobby joinable checking
if (serverStatusData.Motd.isEmpty() || serverStatusData.Motd.equals(""))
{
if (serverStatusData.MaxPlayers - serverStatusData.Players > 20)
{
if (free)
_freeJoinableCount++;
else
_joinableCount++;
}
}
else
{
if (free)
_freeJoinableCount++;
else
_joinableCount++;
}
}
}
if (free)
_freeTotalCount++;
else
_totalCount++;
if (serverStatusData.Empty)
{
EmptyServers.add(serverStatusData);
}
if (free)
{
FreeServers.put(Integer.parseInt(serverStatusData.Name.split("-")[1]), serverStatusData);
}
else
{
Servers.put(Integer.parseInt(serverStatusData.Name.split("-")[1]), serverStatusData);
}
}
private boolean checkForDuplicate(HashMap<Integer, ServerStatusData> serverMap, ServerStatusData serverStatusData, boolean free)
{
if (serverMap.containsKey(Integer.parseInt(serverStatusData.Name.split("-")[1])))
{
ServerStatusData existingServer = serverMap.get(Integer.parseInt(serverStatusData.Name.split("-")[1]));
int existingCount = existingServer.Players;
int newCount = serverStatusData.Players;
if (newCount == 0 || newCount < existingCount)
{
KillServers.add(serverStatusData);
return true;
}
else if (existingCount == 0 || newCount > existingCount)
{
KillServers.add(existingServer);
Players -= existingServer.Players;
MaxPlayers -= existingServer.MaxPlayers;
if (existingServer.Motd != null && (existingServer.Motd.contains("Starting") || existingServer.Motd.contains("Recruiting") || existingServer.Motd.contains("Waiting") || existingServer.Motd.contains("Cup") || existingServer.Motd.isEmpty() || existingServer.Motd.equals("")))
{
if (existingServer.Players < existingServer.MaxPlayers)
{
// Lobby joinable checking
if (existingServer.Motd.isEmpty() || existingServer.Motd.equals(""))
{
if (serverStatusData.MaxPlayers - serverStatusData.Players > 20)
{
if (free)
_freeJoinableCount--;
else
_joinableCount--;
}
}
else
{
if (free)
_freeJoinableCount--;
else
_joinableCount--;
}
}
}
}
}
return false;
}
public int getTotalServers(boolean free)
{
return free ? _freeTotalCount : _totalCount;
}
public int getJoinableCount(boolean free)
{
return free ? _freeJoinableCount : _joinableCount;
}
public int getNextServerNumber(boolean free)
{
if (free)
_freeServerNum++;
else
_serverNum++;
while (true)
{
if (free)
{
if (!FreeServers.containsKey(_freeServerNum))
break;
}
else
{
if (!Servers.containsKey(_serverNum))
break;
}
if (free)
_freeServerNum++;
else
_serverNum++;
}
if (free)
return _freeServerNum;
else
return _serverNum;
}
}

View File

@ -1,450 +0,0 @@
package mineplex.servermonitor;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
public class Repository
{
private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/ServerStatus?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
private String _userName = "root";
private String _password = "tAbechAk3wR7tuTh";
private boolean _us = true;
private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS ServerStatus (id INT NOT NULL AUTO_INCREMENT, serverName VARCHAR(256), serverGroup VARCHAR(256), address VARCHAR(256), port VARCHAR(11), updated LONG, lastTimeWithPlayers LONG, motd VARCHAR(256), players INT, maxPlayers INT, tps INT, ram INT, maxRam INT, PRIMARY KEY (id));";
private static String RETRIEVE_OLD_SERVER_STATUSES = "SELECT ServerStatus.serverName, DynamicServers.address, ServerStatus.address, ServerStatus.port, motd, players, maxPlayers, now(), updated FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address = DynamicServers.privateAddress WHERE DynamicServers.US = ?;";
private static String CREATE_DYNAMIC_TABLE = "CREATE TABLE IF NOT EXISTS DynamicServers (id INT NOT NULL AUTO_INCREMENT, serverName VARCHAR(256), address VARCHAR(256), privateAddress VARCHAR(256), US BOOLEAN NOT NULL DEFAULT 'true', PRIMARY KEY (id));";
private static String RETRIEVE_AVAILABLE_SERVERS = "SELECT DynamicServers.serverName, DynamicServers.address, DynamicServers.privateAddress, DynamicServers.US, DynamicServers.availableCpu, DynamicServers.availableRam, ServerStatus.serverGroup, COUNT(*) As serverCount FROM DynamicServers LEFT JOIN ServerStatus ON ServerStatus.address = DynamicServers.privateAddress WHERE DynamicServers.US = ? GROUP BY DynamicServers.address, ServerStatus.serverGroup;";
private static String RETRIEVE_SERVERGROUP_STATUSES = "SELECT ServerStatus.serverName, serverGroup, motd, DynamicServers.address, ServerStatus.address, ServerStatus.port, players, maxPlayers, case when TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.lastTimeWithPlayers)) > 300 then 1 else 0 end as empty, now(), updated FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address = DynamicServers.privateAddress WHERE DynamicServers.US = ?";
private static String RETRIEVE_SERVER_GROUP_DATA = "SELECT groupName, prefix, scriptName, requiredRam, cpuRequired, requiredTotal, requiredJoinable, arcadeGroup, worldZip, plugin, configPath, minPlayers, maxPlayers, pvp, tournament, generateFreeVersions, games, serverType, addNoCheat, portSection FROM ServerGroups;";
private static String DELETE_SERVER_STATUS = "DELETE FROM ServerStatus WHERE address = ? AND port = ? AND serverName = ?;";
public static Connection connection;
public void initialize(boolean us)
{
_us = us;
PreparedStatement preparedStatement = null;
try
{
Class.forName("com.mysql.jdbc.Driver");
if (connection == null || connection.isClosed())
connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table
preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
preparedStatement = null;
try
{
Class.forName("com.mysql.jdbc.Driver");
// Create table
preparedStatement = connection.prepareStatement(CREATE_DYNAMIC_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
public List<ServerStatusData> retrieveOldServerStatuses()
{
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
List<ServerStatusData> serverData = new ArrayList<ServerStatusData>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try
{
if (connection == null || connection.isClosed())
connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = connection.prepareStatement(RETRIEVE_OLD_SERVER_STATUSES);
preparedStatement.setBoolean(1, _us);
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
{
ServerStatusData serverStatusData = new ServerStatusData();
serverStatusData.Name = resultSet.getString(1);
serverStatusData.Address = resultSet.getString(2);
serverStatusData.PrivateAddress = resultSet.getString(3);
serverStatusData.Port = Integer.parseInt(resultSet.getString(4));
serverStatusData.Motd = resultSet.getString(5);
serverStatusData.Players = resultSet.getInt(6);
serverStatusData.MaxPlayers = resultSet.getInt(7);
long current = dateFormat.parse(resultSet.getString(8)).getTime();
long updated = dateFormat.parse(resultSet.getString(9)).getTime();
if (current - updated > 15000)
serverData.add(serverStatusData);
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null)
{
try
{
resultSet.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
return serverData;
}
public HashMap<String, GroupStatusData> retrieveGroupStatusData()
{
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
HashMap<String, GroupStatusData> groupData = new HashMap<String, GroupStatusData>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try
{
if (connection == null || connection.isClosed())
connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = connection.prepareStatement(RETRIEVE_SERVERGROUP_STATUSES);
preparedStatement.setBoolean(1, _us);
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
{
ServerStatusData serverStatusData = new ServerStatusData();
serverStatusData.Name = resultSet.getString(1);
String serverGroup = resultSet.getString(2);
serverStatusData.Motd = resultSet.getString(3);
serverStatusData.Address = resultSet.getString(4);
serverStatusData.PrivateAddress = resultSet.getString(5);
serverStatusData.Port = Integer.parseInt(resultSet.getString(6));
serverStatusData.Players = resultSet.getInt(7);
serverStatusData.MaxPlayers = resultSet.getInt(8);
serverStatusData.Empty = resultSet.getBoolean(9);
if (!groupData.containsKey(serverGroup))
{
groupData.put(serverGroup, new GroupStatusData());
}
long current = dateFormat.parse(resultSet.getString(10)).getTime();
long updated = dateFormat.parse(resultSet.getString(11)).getTime();
if (current - updated < 15000)
groupData.get(serverGroup).addServer(serverStatusData);
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null)
{
try
{
resultSet.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
return groupData;
}
public Collection<DynamicServerData> retrieveDynamicServers()
{
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
HashMap<String, DynamicServerData> serverMap = new HashMap<String, DynamicServerData>();
HashMap<String, ServerGroupData> serverGroupMap = new HashMap<String, ServerGroupData>();
try
{
if (connection == null || connection.isClosed())
connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_GROUP_DATA);
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
{
ServerGroupData serverGroupData = new ServerGroupData();
serverGroupData.Name = resultSet.getString(1);
serverGroupData.Prefix = resultSet.getString(2);
serverGroupData.ScriptName = resultSet.getString(3);
serverGroupData.RequiredRAM = resultSet.getInt(4);
serverGroupData.RequiredCPU = resultSet.getInt(5);
serverGroupData.RequiredTotalServers = resultSet.getInt(6);
serverGroupData.RequiredJoinableServers = resultSet.getInt(7);
if (!serverGroupMap.containsKey(serverGroupData.Name))
serverGroupMap.put(serverGroupData.Name, serverGroupData);
}
preparedStatement.close();
resultSet.close();
preparedStatement = connection.prepareStatement(RETRIEVE_AVAILABLE_SERVERS);
preparedStatement.setBoolean(1, _us);
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
{
DynamicServerData dynamicServer = new DynamicServerData();
dynamicServer.Name = resultSet.getString(1);
dynamicServer.Address = resultSet.getString(2);
dynamicServer.PrivateAddress = resultSet.getString(3);
dynamicServer.US = resultSet.getBoolean(4);
dynamicServer.AvailableCPU = resultSet.getInt(5);
dynamicServer.AvailableRAM = resultSet.getInt(6);
if (!serverMap.containsKey(dynamicServer.Name))
serverMap.put(dynamicServer.Name, dynamicServer);
String serverGroupName = resultSet.getString(7);
if (serverGroupMap.containsKey(serverGroupName))
serverMap.get(dynamicServer.Name).setServerGroupCount(serverGroupMap.get(serverGroupName), resultSet.getInt(8));
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null)
{
try
{
resultSet.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
return serverMap.values();
}
public Collection<ServerGroupData> retrieveServerGroups()
{
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
HashMap<String, ServerGroupData> serverGroupMap = new HashMap<String, ServerGroupData>();
try
{
if (connection == null || connection.isClosed())
connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_GROUP_DATA);
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
{
ServerGroupData serverGroupData = new ServerGroupData();
serverGroupData.Name = resultSet.getString(1);
serverGroupData.Prefix = resultSet.getString(2);
serverGroupData.ScriptName = resultSet.getString(3);
serverGroupData.RequiredRAM = resultSet.getInt(4);
serverGroupData.RequiredCPU = resultSet.getInt(5);
serverGroupData.RequiredTotalServers = resultSet.getInt(6);
serverGroupData.RequiredJoinableServers = resultSet.getInt(7);
serverGroupData.ArcadeGroup = resultSet.getBoolean(8);
serverGroupData.WorldZip = resultSet.getString(9);
serverGroupData.Plugin = resultSet.getString(10);
serverGroupData.ConfigPath = resultSet.getString(11);
serverGroupData.MinPlayers = resultSet.getInt(12);
serverGroupData.MaxPlayers = resultSet.getInt(13);
serverGroupData.Pvp = resultSet.getBoolean(14);
serverGroupData.Tournament = resultSet.getBoolean(15);
serverGroupData.GenerateFreeVersions = resultSet.getBoolean(16);
serverGroupData.Games = resultSet.getString(17);
serverGroupData.ServerType = resultSet.getString(18);
serverGroupData.AddNoCheat = resultSet.getBoolean(19);
serverGroupData.PortSection = resultSet.getInt(20);
if (!serverGroupMap.containsKey(serverGroupData.Name))
serverGroupMap.put(serverGroupData.Name, serverGroupData);
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null)
{
try
{
resultSet.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
return serverGroupMap.values();
}
public void removeServerRecord(ServerStatusData serverToKill)
{
PreparedStatement preparedStatement = null;
try
{
if (connection == null || connection.isClosed())
connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = connection.prepareStatement(DELETE_SERVER_STATUS);
preparedStatement.setString(1, serverToKill.PrivateAddress);
preparedStatement.setString(2, serverToKill.Port + "");
preparedStatement.setString(3, serverToKill.Name);
preparedStatement.execute();
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
}

View File

@ -1,26 +0,0 @@
package mineplex.servermonitor;
public class ServerGroupData
{
public String Name;
public String Prefix;
public String ScriptName;
public int RequiredRAM;
public int RequiredCPU;
public int RequiredTotalServers;
public int RequiredJoinableServers;
public int PortSection;
public boolean ArcadeGroup;
public String WorldZip;
public String Plugin;
public String ConfigPath;
public int MinPlayers;
public int MaxPlayers;
public boolean Pvp;
public boolean Tournament;
public boolean GenerateFreeVersions;
public String Games;
public String ServerType;
public boolean AddNoCheat;
}

View File

@ -39,10 +39,9 @@ public class ServerMonitor
public static void main (String args[])
{
<<<<<<< HEAD
Region region = !new File("eu.dat").exists() ? Region.US : Region.EU;
_repository = ServerManager.getServerRepository(region); // Fetches and connects to server repo
=======
File logFile = new File("monitor.log");
if (!logFile.exists())
@ -69,9 +68,6 @@ public class ServerMonitor
e1.printStackTrace();
}
_us = !new File("eu.dat").exists();
>>>>>>> 5d1ab654b914b97d69d2cf635edb15c03502c790
HashMap<String, Entry<String, Long>> serverTracker = new HashMap<String, Entry<String, Long>>();
while (true)
@ -79,8 +75,6 @@ public class ServerMonitor
Collection<ServerGroup> serverGroups = _repository.getServerGroups();
_repository.clean(); // Clean out old expired server entries
<<<<<<< HEAD
List<DedicatedServer> dedicatedServers = new ArrayList<DedicatedServer>(_repository.getDedicatedServers());
if (_count % 15 == 0)
@ -140,140 +134,13 @@ public class ServerMonitor
for (ServerGroup serverGroup : serverGroups)
{
int serverNum = serverGroup.generateUniqueId();
//GroupStatusData groupStatus = groupStatusList.get(serverGroup.Name);
int requiredTotal = serverGroup.getRequiredTotalServers();
int requiredJoinable = serverGroup.getRequiredJoinableServers();
int joinableServers = serverGroup.getJoinableCount();
int totalServers = serverGroup.getServerCount();
int serversToAdd = Math.max(requiredTotal - totalServers, requiredJoinable - joinableServers);
int serversToKill = (totalServers > requiredTotal && joinableServers > requiredJoinable) ? Math.min(joinableServers - requiredJoinable, serverGroup.getEmptyServers().size()) : 0;
handleGroupChanges(dedicatedServers, serverTracker, serverGroup, false);
if (serverGroup.getGenerateFreeVersions() && _count % 6 == 0)
{
handleGroupChanges(dedicatedServers, serverTracker, serverGroup, true);
}
// Minimum 1500 slot bufferzone
if (serverGroup.getName().equalsIgnoreCase("Lobby"))
{
if (serverGroup.getMaxPlayerCount() - serverGroup.getPlayerCount() < 1500)
serversToAdd = requiredJoinable;
}
while (serversToAdd > 0)
{
Collections.sort(dedicatedServers, new DedicatedServerSorter());
DedicatedServer bestServer = getBestDedicatedServer(dedicatedServers, serverGroup);
if (bestServer == null)
{
System.out.println("No best dynamic server available for group " + serverGroup.getName());
break;
}
if (serverTracker.containsKey(serverGroup.getPrefix() + "-" + serverNum))
System.out.println("[WAITING] On " + serverGroup.getPrefix() + "-" + serverNum + " to finish starting...");
else
{
startServer(bestServer, serverGroup, serverNum);
serverTracker.put(serverGroup.getPrefix() + "-" + serverNum, new AbstractMap.SimpleEntry<String, Long>(bestServer.getPublicAddress(), System.currentTimeMillis()));
}
serversToAdd--;
}
while (serversToKill > 0)
{
List<MinecraftServer> emptyServers = new ArrayList<MinecraftServer>(serverGroup.getEmptyServers());
MinecraftServer emptyServer = emptyServers.get(0);
System.out.println("[" + emptyServer.getName() + ":" + emptyServer.getPublicAddress() + "] Killing " + serverGroup.getName() + " Req Total: " + serverGroup.getRequiredTotalServers() + " Req Joinable: " + serverGroup.getRequiredJoinableServers() + " | Actual Total: " + serverGroup.getServerCount() + " Actual Joinable: " + serverGroup.getJoinableCount());
killServer(emptyServer);
serversToKill--;
}
=======
for (ServerStatusData statusData : _repository.retrieveOldServerStatuses())
{
killServer(statusData);
}
List<DynamicServerData> dynamicServers = new ArrayList<DynamicServerData>(_repository.retrieveDynamicServers());
if (_count % 15 == 0)
{
_badServers.clear();
for (DynamicServerData serverData : dynamicServers)
{
if (isServerOffline(serverData))
{
System.out.println("------=[OFFLINE]=------=[" + serverData.Name + ":" + serverData.Address + "]=------=[OFFLINE]=------");
log(serverData.Name + ":" + serverData.Address + " is OFFLINE.");
_badServers.put(serverData.Name, true);
}
}
}
for (Iterator<DynamicServerData> iterator = dynamicServers.iterator(); iterator.hasNext();)
{
DynamicServerData serverData = iterator.next();
if (_badServers.containsKey(serverData.Name))
iterator.remove();
}
for (GroupStatusData groupStatus : groupStatusList.values())
{
for (ServerStatusData serverToKill : groupStatus.KillServers)
{
System.out.println("----DUPLICATE SERVER----> " + serverToKill.Address + ", " + serverToKill.Name);
log("Duplicate server " + serverToKill.Name + ":" + serverToKill.Address + " is being killed.");
killServer(serverToKill);
}
for (ServerStatusData serverToKill : groupStatus.Servers.values())
{
if (serverTracker.containsKey(serverToKill.Name))
serverTracker.remove(serverToKill.Name);
}
for (ServerStatusData serverToKill : groupStatus.FreeServers.values())
{
if (serverTracker.containsKey(serverToKill.Name))
serverTracker.remove(serverToKill.Name);
}
}
for (Iterator<Entry<String, Entry<String, Long>>> iterator = serverTracker.entrySet().iterator(); iterator.hasNext();)
{
Entry<String, Entry<String, Long>> entry = iterator.next();
if (System.currentTimeMillis() - entry.getValue().getValue() > 15000)
{
System.out.println("-=[SERVER STARTUP TOO SLOW]=- " + entry.getKey());
ServerStatusData serverToKill = new ServerStatusData();
serverToKill.Name = entry.getKey();
serverToKill.Address = entry.getValue().getKey();
log("Server startup too slow " + serverToKill.Name + ":" + serverToKill.Address + " is being killed.");
killServer(serverToKill);
iterator.remove();
}
}
for (ServerGroupData serverGroup : serverGroups)
{
if (!groupStatusList.containsKey(serverGroup.Name))
{
groupStatusList.put(serverGroup.Name, new GroupStatusData());
}
GroupStatusData groupStatus = groupStatusList.get(serverGroup.Name);
handleGroupChanges(dynamicServers, serverTracker, serverGroup, groupStatus, false);
if (serverGroup.GenerateFreeVersions && _count % 6 == 0)
{
handleGroupChanges(dynamicServers, serverTracker, serverGroup, groupStatus, true);
}
>>>>>>> 5d1ab654b914b97d69d2cf635edb15c03502c790
}
int processWaits = 0;
@ -340,42 +207,41 @@ public class ServerMonitor
}
}
<<<<<<< HEAD
private static void killServer(final String serverName, final String serverAddress, final boolean announce)
=======
private static void handleGroupChanges(List<DynamicServerData> dynamicServers, HashMap<String, Entry<String, Long>> serverTracker, ServerGroupData serverGroup, GroupStatusData groupStatus, boolean free)
private static void handleGroupChanges(List<DedicatedServer> dedicatedServers, HashMap<String, Entry<String, Long>> serverTracker, ServerGroup serverGroup, boolean free)
{
int serversToAdd = Math.max(serverGroup.RequiredTotalServers - groupStatus.getTotalServers(free), serverGroup.RequiredJoinableServers - groupStatus.getJoinableCount(free));
int serversToKill = (groupStatus.getTotalServers(free) > serverGroup.RequiredTotalServers && groupStatus.getJoinableCount(free) > serverGroup.RequiredJoinableServers) ? Math.min(groupStatus.getJoinableCount(free) - serverGroup.RequiredJoinableServers, groupStatus.EmptyServers.size()) : 0;
int serverNum = serverGroup.generateUniqueId();
//GroupStatusData groupStatus = groupStatusList.get(serverGroup.Name);
int requiredTotal = serverGroup.getRequiredTotalServers();
int requiredJoinable = serverGroup.getRequiredJoinableServers();
int joinableServers = serverGroup.getJoinableCount();
int totalServers = serverGroup.getServerCount();
int serversToAdd = Math.max(requiredTotal - totalServers, requiredJoinable - joinableServers);
int serversToKill = (totalServers > requiredTotal && joinableServers > requiredJoinable) ? Math.min(joinableServers - requiredJoinable, serverGroup.getEmptyServers().size()) : 0;
if (free)
serversToAdd = Math.min(1, serversToAdd);
// Minimum 1500 slot bufferzone
if (serverGroup.Name.equalsIgnoreCase("Lobby"))
if (serverGroup.getName().equalsIgnoreCase("Lobby"))
{
if (groupStatus.MaxPlayers - groupStatus.Players < 1500)
serversToAdd = serverGroup.RequiredJoinableServers;
if (serverGroup.getMaxPlayerCount() - serverGroup.getPlayerCount() < 1500)
serversToAdd = requiredJoinable;
}
while (serversToAdd > 0)
{
int serverNum = groupStatus.getNextServerNumber(free);
Collections.sort(dynamicServers, new DynamicServerSorter());
DynamicServerData bestServer = getBestDynamicServer(dynamicServers, serverGroup);
Collections.sort(dedicatedServers, new DedicatedServerSorter());
DedicatedServer bestServer = getBestDedicatedServer(dedicatedServers, serverGroup);
if (bestServer == null)
{
System.out.println("No best dynamic server available for group " + serverGroup.Name);
System.out.println("No best dynamic server available for group " + serverGroup.getName());
break;
}
if (serverTracker.containsKey(serverGroup.Prefix + "-" + serverNum + (free ? "-FREE" : "")))
System.out.println("[WAITING] On " + serverGroup.Prefix + "-" + serverNum + " to finish starting...");
if (serverTracker.containsKey(serverGroup.getPrefix() + "-" + serverNum))
System.out.println("[WAITING] On " + serverGroup.getPrefix() + "-" + serverNum + " to finish starting...");
else
{
startServer(bestServer, serverGroup, serverNum, free);
serverTracker.put(serverGroup.Prefix + "-" + serverNum + (free ? "-FREE" : ""), new AbstractMap.SimpleEntry<String, Long>(bestServer.Address, System.currentTimeMillis()));
serverTracker.put(serverGroup.getPrefix() + "-" + serverNum, new AbstractMap.SimpleEntry<String, Long>(bestServer.getPublicAddress(), System.currentTimeMillis()));
}
serversToAdd--;
@ -383,15 +249,15 @@ public class ServerMonitor
while (serversToKill > 0)
{
System.out.println("[" + groupStatus.EmptyServers.get(0).Name + ":" + groupStatus.EmptyServers.get(0).Address + "] Killing " + serverGroup.Name + " " + (free ? "FREE" : "PREMIUM") + " Req Total: " + serverGroup.RequiredTotalServers + " Req Joinable: " + serverGroup.RequiredJoinableServers + " | Actual Total: " + groupStatus.getTotalServers(free) + " Actual Joinable: " + groupStatus.getJoinableCount(free));
log("Excess server " + groupStatus.EmptyServers.get(0).Name + ":" + groupStatus.EmptyServers.get(0).Address + " is being killed.");
killServer(groupStatus.EmptyServers.remove(0));
List<MinecraftServer> emptyServers = new ArrayList<MinecraftServer>(serverGroup.getEmptyServers());
MinecraftServer emptyServer = emptyServers.get(0);
System.out.println("[" + emptyServer.getName() + ":" + emptyServer.getPublicAddress() + "] Killing " + serverGroup.getName() + " Req Total: " + serverGroup.getRequiredTotalServers() + " Req Joinable: " + serverGroup.getRequiredJoinableServers() + " | Actual Total: " + serverGroup.getServerCount() + " Actual Joinable: " + serverGroup.getJoinableCount());
killServer(emptyServer);
serversToKill--;
}
}
private static void killServer(final ServerStatusData serverToKill, final boolean announce)
>>>>>>> 5d1ab654b914b97d69d2cf635edb15c03502c790
private static void killServer(final String serverName, final String serverAddress, final boolean announce)
{
String cmd = "/home/mineplex/easyRemoteKillServer.sh";
@ -495,36 +361,23 @@ public class ServerMonitor
killServer(serverToKill.getName(), serverToKill.getPublicAddress(), true);
}
<<<<<<< HEAD
private static void startServer(final DedicatedServer serverSpace, final ServerGroup serverGroup, final int serverNum)
private static void startServer(final DedicatedServer serverSpace, final ServerGroup serverGroup, final int serverNum, final boolean free)
{
String cmd = "/home/mineplex/easyRemoteStartServer.sh";
final String groupPrefix = serverGroup.getPrefix();
final String serverName = serverSpace.getName();
final String serverAddress = serverSpace.getPublicAddress();
ProcessRunner pr = new ProcessRunner(new String[] {"/bin/sh", cmd, serverSpace.getPublicAddress(), serverSpace.getPrivateAddress(), serverGroup.getScriptName(), groupPrefix + "-" + serverNum, "1", serverSpace.isUsRegion() ? "us" : "eu"});
=======
private static void startServer(final DynamicServerData serverSpace, final ServerGroupData serverGroup, final int serverNum, final boolean free)
{
String cmd = "/home/mineplex/easyRemoteStartServerCustom.sh";
ProcessRunner pr = new ProcessRunner(new String[] {"/bin/sh", cmd, serverSpace.Address, serverSpace.PrivateAddress, serverGroup.PortSection + serverNum + "", serverGroup.RequiredRAM + "", serverGroup.WorldZip, serverGroup.Plugin, serverGroup.ConfigPath, serverGroup.Name, serverGroup.Prefix + "-" + serverNum, serverGroup.MinPlayers + "", serverGroup.MaxPlayers + "", serverGroup.Pvp + "", serverGroup.Tournament + "", free + "", serverSpace.US ? "true" : "false", serverGroup.ArcadeGroup + "", serverGroup.Games, serverGroup.ServerType, serverGroup.AddNoCheat + ""});
>>>>>>> 5d1ab654b914b97d69d2cf635edb15c03502c790
ProcessRunner pr = new ProcessRunner(new String[] {"/bin/sh", cmd, serverAddress, serverSpace.getPrivateAddress(), serverGroup.getPortSection() + serverNum + "", serverGroup.getRequiredRam() + "", serverGroup.getWorldZip(), serverGroup.getPlugin(), serverGroup.getConfigPath(), serverGroup.getName(), serverGroup.getPrefix() + "-" + serverNum, serverGroup.getMinPlayers() + "", serverGroup.getMaxPlayers() + "", serverGroup.getPvp() + "", serverGroup.getTournament() + "", free + "", serverSpace.isUsRegion() ? "true" : "false", serverGroup.getArcadeGroup() + "", serverGroup.getGames(), serverGroup.getServerType(), serverGroup.getAddNoCheat() + ""});
pr.start(new GenericRunnable<Boolean>()
{
public void run(Boolean error)
{
if (error)
<<<<<<< HEAD
System.out.println("[" + serverName + ":" + serverAddress + "] Errored " + serverName + "(" + groupPrefix+ "-" + serverNum + ")");
System.out.println("[" + serverName + ":" + serverAddress + "] Errored " + serverName + "(" + groupPrefix+ "-" + serverNum + (free ? "-FREE" : "") + ")");
else
System.out.println("[" + serverName + ":" + serverAddress + "] Added " + serverName + "(" + groupPrefix+ "-" + serverNum + ")");
=======
System.out.println("[" + serverSpace.Name + ":" + serverSpace.Address + "] Errored " + serverGroup.Name + "(" + serverGroup.Prefix + "-" + serverNum + (free ? "-FREE" : "") + ")");
else
System.out.println("[" + serverSpace.Name + ":" + serverSpace.Address + "] Added " + serverGroup.Name + "(" + serverGroup.Prefix + "-" + serverNum + (free ? "-FREE" : "") + ")");
>>>>>>> 5d1ab654b914b97d69d2cf635edb15c03502c790
System.out.println("[" + serverName + ":" + serverAddress + "] Added " + serverName + "(" + groupPrefix+ "-" + serverNum + (free ? "-FREE" : "") + ")");
}
});