Optimized mysql queries with server status' address/updated fields.

Removed double gems.
Added BETA check for Hero only beta games.
This commit is contained in:
Jonathan Williams 2014-03-03 12:47:57 -08:00
parent b3f10b9d62
commit d99a3c9253
11 changed files with 112 additions and 81 deletions

Binary file not shown.

View File

@ -13,6 +13,7 @@ import java.util.Map;
import mineplex.bungee.lobbyBalancer.LobbyBalancer; import mineplex.bungee.lobbyBalancer.LobbyBalancer;
import mineplex.bungee.motd.MotdManager; import mineplex.bungee.motd.MotdManager;
import mineplex.bungee.playerCount.PlayerCount; import mineplex.bungee.playerCount.PlayerCount;
import mineplex.bungee.playerStats.PlayerStats;
import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.conf.YamlConfig; import net.md_5.bungee.conf.YamlConfig;
@ -66,6 +67,7 @@ public class Mineplexer extends Plugin
new LobbyBalancer(this); new LobbyBalancer(this);
new PlayerCount(this); new PlayerCount(this);
new FileUpdater(this); new FileUpdater(this);
new PlayerStats(this);
} }
protected String readString(DataInputStream dataInputStream, int maxLength) throws IOException protected String readString(DataInputStream dataInputStream, int maxLength) throws IOException

View File

@ -5,6 +5,7 @@ import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -16,8 +17,8 @@ public class LobbyBalancerRepository
private String _password = "tAbechAk3wR7tuTh"; private String _password = "tAbechAk3wR7tuTh";
private boolean _us; private boolean _us;
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), updated LONG, motd VARCHAR(256), players INT, maxPlayers INT, tps INT, ram INT, maxRam INT, PRIMARY KEY (id));"; 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, motd VARCHAR(256), players INT, maxPlayers INT, tps INT, ram INT, maxRam INT, PRIMARY KEY (id));";
private static String RETRIEVE_SERVER_STATUSES = "SELECT ServerStatus.serverName, ServerStatus.address, motd, players, maxPlayers FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address LIKE CONCAT(DynamicServers.privateAddress, '%') WHERE DynamicServers.US = ? AND TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) < 10;"; private static String RETRIEVE_SERVER_STATUSES = "SELECT ServerStatus.serverName, ServerStatus.address, ServerStatus.port, motd, players, maxPlayers, now(), updated FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address = DynamicServers.privateAddress WHERE DynamicServers.US = ?;";
public void initialize(boolean us) public void initialize(boolean us)
{ {
@ -59,6 +60,7 @@ public class LobbyBalancerRepository
ResultSet resultSet = null; ResultSet resultSet = null;
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
List<ServerStatusData> serverData = new ArrayList<ServerStatusData>(); List<ServerStatusData> serverData = new ArrayList<ServerStatusData>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try try
{ {
@ -76,13 +78,16 @@ public class LobbyBalancerRepository
serverStatusData.Name = resultSet.getString(1); serverStatusData.Name = resultSet.getString(1);
String addressPortString = resultSet.getString(2); serverStatusData.Address = resultSet.getString(2);
serverStatusData.Address = addressPortString.split(":")[0]; serverStatusData.Port = Integer.parseInt(resultSet.getString(3));
serverStatusData.Port = Integer.parseInt(addressPortString.split(":")[1]); serverStatusData.Motd = resultSet.getString(4);
serverStatusData.Motd = resultSet.getString(3); serverStatusData.Players = resultSet.getInt(5);
serverStatusData.Players = resultSet.getInt(4); serverStatusData.MaxPlayers = resultSet.getInt(6);
serverStatusData.MaxPlayers = resultSet.getInt(5);
long current = dateFormat.parse(resultSet.getString(7)).getTime();
long updated = dateFormat.parse(resultSet.getString(8)).getTime();
if (current - updated < 10000)
serverData.add(serverStatusData); serverData.add(serverStatusData);
} }
} }

View File

@ -52,7 +52,9 @@ public class ServerStatusManager extends MiniPlugin
plugin.getConfig().getBoolean("serverstatus.us"), plugin.getConfig().getBoolean("serverstatus.us"),
_name, _name,
plugin.getConfig().getString("serverstatus.group"), plugin.getConfig().getString("serverstatus.group"),
address + ":" + _plugin.getServer().getPort(), event.getMaxPlayers() address,
_plugin.getServer().getPort() + "",
event.getMaxPlayers()
); );
if (_enabled) if (_enabled)

View File

@ -6,7 +6,9 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
public class ServerStatusRepository public class ServerStatusRepository
@ -16,22 +18,23 @@ public class ServerStatusRepository
private String _password; private String _password;
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), updated LONG, lastTimeWithPlayers LONG, motd VARCHAR(256), players INT, maxPlayers INT, tps INT, ram INT, maxRam INT, PRIMARY KEY (id));"; 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), updated LONG, lastTimeWithPlayers LONG, motd VARCHAR(256), players INT, maxPlayers INT, tps INT, ram INT, maxRam INT, PRIMARY KEY (id));";
private static String INSERT_PLAYER_COUNT = "INSERT INTO ServerStatus (serverName, serverGroup, address, updated, motd, players, maxPlayers, tps, ram, maxRam) values(?, ?, ?, now(), 'Configuring server.', ?, ?, 0, ?, ?);"; private static String INSERT_PLAYER_COUNT = "INSERT INTO ServerStatus (serverName, serverGroup, address, port, updated, motd, players, maxPlayers, tps, ram, maxRam) values(?, ?, ?, ?, now(), 'Configuring server.', ?, ?, 0, ?, ?);";
private static String UPDATE_PLAYER_COUNT_WITH_PLAYERS = "UPDATE ServerStatus SET updated = now(), serverName = ?, serverGroup = ?, motd = ?, players = ?, maxPlayers = ?, tps = ?, ram = ?, maxRam = ?, lastTimeWithPlayers = now() WHERE id = ?;"; private static String UPDATE_PLAYER_COUNT_WITH_PLAYERS = "UPDATE ServerStatus SET updated = now(), serverName = ?, serverGroup = ?, motd = ?, players = ?, maxPlayers = ?, tps = ?, ram = ?, maxRam = ?, lastTimeWithPlayers = now() WHERE id = ?;";
private static String UPDATE_PLAYER_COUNT_WITHOUT_PLAYERS = "UPDATE ServerStatus SET updated = now(), serverName = ?, serverGroup = ?, motd = ?, players = ?, maxPlayers = ?, tps = ?, ram = ?, maxRam = ? WHERE id = ?;"; private static String UPDATE_PLAYER_COUNT_WITHOUT_PLAYERS = "UPDATE ServerStatus SET updated = now(), serverName = ?, serverGroup = ?, motd = ?, players = ?, maxPlayers = ?, tps = ?, ram = ?, maxRam = ? WHERE id = ?;";
private static String RETRIEVE_ID = "SELECT id FROM ServerStatus WHERE address = ?;"; private static String RETRIEVE_ID = "SELECT id FROM ServerStatus WHERE address = ? AND port = ?;";
private static String RETRIEVE_SERVER_STATUSES = "SELECT ServerStatus.serverName, motd, players, maxPlayers FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address LIKE CONCAT(DynamicServers.privateAddress, '%') WHERE DynamicServers.US = ? AND TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) < 10;"; private static String RETRIEVE_SERVER_STATUSES = "SELECT ServerStatus.serverName, motd, players, maxPlayers, now(), updated FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address = DynamicServers.privateAddress WHERE DynamicServers.US = ?";
private int _id = -1; private int _id = -1;
private boolean _us; private boolean _us;
private String _serverName; private String _serverName;
private String _serverGroup; private String _serverGroup;
private String _address; private String _address;
private String _port;
private int _maxPlayers = 0; private int _maxPlayers = 0;
Connection _connection = null; Connection _connection = null;
public ServerStatusRepository(String connectionUrl, String username, String password, boolean us, String serverName, String serverGroup, String address, int maxPlayers) public ServerStatusRepository(String connectionUrl, String username, String password, boolean us, String serverName, String serverGroup, String address, String port, int maxPlayers)
{ {
_connectionString = connectionUrl; _connectionString = connectionUrl;
_userName = username; _userName = username;
@ -40,6 +43,7 @@ public class ServerStatusRepository
_serverName = serverName; _serverName = serverName;
_serverGroup = serverGroup; _serverGroup = serverGroup;
_address = address; _address = address;
_port = port;
_maxPlayers = maxPlayers; _maxPlayers = maxPlayers;
} }
@ -62,6 +66,7 @@ public class ServerStatusRepository
// Retrieve id // Retrieve id
preparedStatementRetrieve = _connection.prepareStatement(RETRIEVE_ID); preparedStatementRetrieve = _connection.prepareStatement(RETRIEVE_ID);
preparedStatementRetrieve.setString(1, _address); preparedStatementRetrieve.setString(1, _address);
preparedStatementRetrieve.setString(2, _port);
resultSet = preparedStatementRetrieve.executeQuery(); resultSet = preparedStatementRetrieve.executeQuery();
while (resultSet.next()) while (resultSet.next())
@ -77,10 +82,11 @@ public class ServerStatusRepository
preparedStatementInsert.setString(1, _serverName); preparedStatementInsert.setString(1, _serverName);
preparedStatementInsert.setString(2, _serverGroup); preparedStatementInsert.setString(2, _serverGroup);
preparedStatementInsert.setString(3, _address); preparedStatementInsert.setString(3, _address);
preparedStatementInsert.setInt(4, 0); preparedStatementInsert.setString(4, _port);
preparedStatementInsert.setInt(5, _maxPlayers); preparedStatementInsert.setInt(5, 0);
preparedStatementInsert.setInt(6, (int) ((Runtime.getRuntime().maxMemory() - Runtime.getRuntime().freeMemory()) / 1048576)); preparedStatementInsert.setInt(6, _maxPlayers);
preparedStatementInsert.setInt(7, (int) (Runtime.getRuntime().maxMemory() / 1048576)); preparedStatementInsert.setInt(7, (int) ((Runtime.getRuntime().maxMemory() - Runtime.getRuntime().freeMemory()) / 1048576));
preparedStatementInsert.setInt(8, (int) (Runtime.getRuntime().maxMemory() / 1048576));
int affectedRows = preparedStatementInsert.executeUpdate(); int affectedRows = preparedStatementInsert.executeUpdate();
@ -216,6 +222,7 @@ public class ServerStatusRepository
ResultSet resultSet = null; ResultSet resultSet = null;
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
List<ServerStatusData> serverData = new ArrayList<ServerStatusData>(); List<ServerStatusData> serverData = new ArrayList<ServerStatusData>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try try
{ {
@ -237,7 +244,10 @@ public class ServerStatusRepository
serverStatusData.Motd = resultSet.getString(2); serverStatusData.Motd = resultSet.getString(2);
serverStatusData.Players = resultSet.getInt(3); serverStatusData.Players = resultSet.getInt(3);
serverStatusData.MaxPlayers = resultSet.getInt(4); serverStatusData.MaxPlayers = resultSet.getInt(4);
long current = dateFormat.parse(resultSet.getString(5)).getTime();
long updated = dateFormat.parse(resultSet.getString(6)).getTime();
if (current - updated < 10000)
serverData.add(serverStatusData); serverData.add(serverStatusData);
} }
} }

View File

@ -390,6 +390,11 @@ public class ServerManager extends MiniPlugin
if (partyPlayer == null) if (partyPlayer == null)
continue; continue;
if ((serverInfo.Name.contains("BETA") && !_clientManager.Get(partyPlayer).GetRank().Has(Rank.HERO)))
{
continue;
}
if (_clientManager.Get(partyPlayer).GetRank().Has(Rank.ULTRA) || _donationManager.Get(partyPlayer.getName()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA")) if (_clientManager.Get(partyPlayer).GetRank().Has(Rank.ULTRA) || _donationManager.Get(partyPlayer.getName()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA"))
continue; continue;
@ -406,6 +411,11 @@ public class ServerManager extends MiniPlugin
if (partyPlayer == null) if (partyPlayer == null)
continue; continue;
if ((serverInfo.Name.contains("BETA") && !_clientManager.Get(partyPlayer).GetRank().Has(Rank.HERO)))
{
continue;
}
if (_clientManager.Get(partyPlayer).GetRank().Has(Rank.ULTRA) || _donationManager.Get(partyPlayer.getName()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA")) if (_clientManager.Get(partyPlayer).GetRank().Has(Rank.ULTRA) || _donationManager.Get(partyPlayer.getName()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA"))
{ {
partyPlayer.leaveVehicle(); partyPlayer.leaveVehicle();

View File

@ -63,11 +63,14 @@ public class ServerNpcPage extends ShopPageBase<ServerManager, ServerNpcShop> im
int greenCount = 0; int greenCount = 0;
int yellowCount = 0; int yellowCount = 0;
String openFull = ChatColor.RESET + C.Line + "Get Ultra to join full servers!"; String openFull = ChatColor.RESET + C.Line + "Get Ultra to join full servers!";
String beta = ChatColor.RESET + C.Line + "Get Hero to join Beta servers!";
String openFullUltra = ChatColor.RESET + C.Line + "Click to join!"; String openFullUltra = ChatColor.RESET + C.Line + "Click to join!";
for (ServerInfo serverInfo : serverList) for (ServerInfo serverInfo : serverList)
{ {
boolean ownsUltraPackage = DonationManager.Get(Player.getName()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA") || Client.GetRank().Has(Rank.ULTRA); boolean ownsUltraPackage = DonationManager.Get(Player.getName()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA") || Client.GetRank().Has(Rank.ULTRA);
boolean hero = Client.GetRank().Has(Rank.HERO);
String inProgress = (serverInfo.Game == null || serverInfo.ServerType.equalsIgnoreCase("Competitive")) ? (ChatColor.RESET + C.Line + "Game in progress.") : (ChatColor.RESET + C.Line + "Click to spectate"); String inProgress = (serverInfo.Game == null || serverInfo.ServerType.equalsIgnoreCase("Competitive")) ? (ChatColor.RESET + C.Line + "Game in progress.") : (ChatColor.RESET + C.Line + "Click to spectate");
String inProgressLine2 = (serverInfo.Game == null || serverInfo.ServerType.equalsIgnoreCase("Competitive")) ? null : (ChatColor.RESET + C.Line + "and wait for next game!"); String inProgressLine2 = (serverInfo.Game == null || serverInfo.ServerType.equalsIgnoreCase("Competitive")) ? null : (ChatColor.RESET + C.Line + "and wait for next game!");
@ -96,6 +99,12 @@ public class ServerNpcPage extends ShopPageBase<ServerManager, ServerNpcShop> im
lore.add(ChatColor.RESET + ""); lore.add(ChatColor.RESET + "");
lore.add(ChatColor.RESET + serverInfo.MOTD); lore.add(ChatColor.RESET + serverInfo.MOTD);
if (serverInfo.Name.contains("BETA") && !hero)
{
lore.add(beta);
}
else
{
if (serverInfo.CurrentPlayers >= serverInfo.MaxPlayers) if (serverInfo.CurrentPlayers >= serverInfo.MaxPlayers)
{ {
if (serverInfo.Game.equalsIgnoreCase("Survival Games")) if (serverInfo.Game.equalsIgnoreCase("Survival Games"))
@ -115,6 +124,7 @@ public class ServerNpcPage extends ShopPageBase<ServerManager, ServerNpcShop> im
{ {
lore.add(ChatColor.RESET + C.Line + "Click to join!"); lore.add(ChatColor.RESET + C.Line + "Click to join!");
} }
}
greenCount++; greenCount++;
} }
@ -194,7 +204,7 @@ public class ServerNpcPage extends ShopPageBase<ServerManager, ServerNpcShop> im
{ {
int slots = Plugin.GetRequiredSlots(player, serverInfo.ServerType); int slots = Plugin.GetRequiredSlots(player, serverInfo.ServerType);
if (serverInfo.MaxPlayers - serverInfo.CurrentPlayers < slots && !(DonationManager.Get(Player.getName()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA") || Client.GetRank().Has(Rank.ULTRA))) if ((serverInfo.Name.contains("BETA") && ! Client.GetRank().Has(Rank.HERO)) || (serverInfo.MaxPlayers - serverInfo.CurrentPlayers < slots && !(DonationManager.Get(Player.getName()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA") || Client.GetRank().Has(Rank.ULTRA))))
{ {
PlayDenySound(player); PlayDenySound(player);
return; return;

View File

@ -5,6 +5,7 @@ import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
@ -16,14 +17,14 @@ public class Repository
private String _userName = "root"; private String _userName = "root";
private String _password = "tAbechAk3wR7tuTh"; private String _password = "tAbechAk3wR7tuTh";
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), updated LONG, lastTimeWithPlayers LONG, motd VARCHAR(256), players INT, maxPlayers INT, tps INT, ram INT, maxRam INT, PRIMARY KEY (id));"; 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, motd, players, maxPlayers FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address LIKE CONCAT(DynamicServers.privateAddress, '%') WHERE DynamicServers.US = true AND TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) > 15;"; 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 = false;";
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 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 LIKE CONCAT(DynamicServers.privateAddress, '%') WHERE DynamicServers.US = true GROUP BY DynamicServers.address, ServerStatus.serverGroup;"; 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 = false GROUP BY DynamicServers.address, ServerStatus.serverGroup;";
private static String RETRIEVE_SERVERGROUP_STATUSES = "SELECT ServerStatus.serverName, serverGroup, motd, DynamicServers.address, ServerStatus.address, players, maxPlayers, case when TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.lastTimeWithPlayers)) > 300 then 1 else 0 end as empty FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address LIKE CONCAT(DynamicServers.privateAddress, '%') WHERE DynamicServers.US = true AND TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) <= 15"; 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 = false";
private static String RETRIEVE_SERVER_GROUP_DATA = "SELECT groupName, prefix, scriptName, requiredRam, cpuRequired, requiredTotal, requiredJoinable FROM ServerGroups;"; private static String RETRIEVE_SERVER_GROUP_DATA = "SELECT groupName, prefix, scriptName, requiredRam, cpuRequired, requiredTotal, requiredJoinable FROM ServerGroups;";
private static String DELETE_SERVER_STATUS = "DELETE FROM ServerStatus WHERE address = ? AND serverName = ?;"; private static String DELETE_SERVER_STATUS = "DELETE FROM ServerStatus WHERE address = ? AND port = ? AND serverName = ?;";
public static Connection connection; public static Connection connection;
@ -96,6 +97,7 @@ public class Repository
ResultSet resultSet = null; ResultSet resultSet = null;
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
List<ServerStatusData> serverData = new ArrayList<ServerStatusData>(); List<ServerStatusData> serverData = new ArrayList<ServerStatusData>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try try
{ {
@ -112,13 +114,16 @@ public class Repository
serverStatusData.Name = resultSet.getString(1); serverStatusData.Name = resultSet.getString(1);
serverStatusData.Address = resultSet.getString(2); serverStatusData.Address = resultSet.getString(2);
String addressPortString = resultSet.getString(3); serverStatusData.PrivateAddress = resultSet.getString(3);
serverStatusData.PrivateAddress = addressPortString.split(":")[0]; serverStatusData.Port = Integer.parseInt(resultSet.getString(4));
serverStatusData.Port = Integer.parseInt(addressPortString.split(":")[1]); serverStatusData.Motd = resultSet.getString(5);
serverStatusData.Motd = resultSet.getString(4); serverStatusData.Players = resultSet.getInt(6);
serverStatusData.Players = resultSet.getInt(5); serverStatusData.MaxPlayers = resultSet.getInt(7);
serverStatusData.MaxPlayers = resultSet.getInt(6);
long current = dateFormat.parse(resultSet.getString(8)).getTime();
long updated = dateFormat.parse(resultSet.getString(9)).getTime();
if (current - updated > 15000)
serverData.add(serverStatusData); serverData.add(serverStatusData);
} }
} }
@ -161,6 +166,7 @@ public class Repository
ResultSet resultSet = null; ResultSet resultSet = null;
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
HashMap<String, GroupStatusData> groupData = new HashMap<String, GroupStatusData>(); HashMap<String, GroupStatusData> groupData = new HashMap<String, GroupStatusData>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try try
{ {
@ -178,18 +184,21 @@ public class Repository
String serverGroup = resultSet.getString(2); String serverGroup = resultSet.getString(2);
serverStatusData.Motd = resultSet.getString(3); serverStatusData.Motd = resultSet.getString(3);
serverStatusData.Address = resultSet.getString(4); serverStatusData.Address = resultSet.getString(4);
String addressPortString = resultSet.getString(5); serverStatusData.PrivateAddress = resultSet.getString(5);
serverStatusData.PrivateAddress = addressPortString.split(":")[0]; serverStatusData.Port = Integer.parseInt(resultSet.getString(6));
serverStatusData.Port = Integer.parseInt(addressPortString.split(":")[1]); serverStatusData.Players = resultSet.getInt(7);
serverStatusData.Players = resultSet.getInt(6); serverStatusData.MaxPlayers = resultSet.getInt(8);
serverStatusData.MaxPlayers = resultSet.getInt(7); serverStatusData.Empty = resultSet.getBoolean(9);
serverStatusData.Empty = resultSet.getBoolean(8);
if (!groupData.containsKey(serverGroup)) if (!groupData.containsKey(serverGroup))
{ {
groupData.put(serverGroup, new GroupStatusData()); 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); groupData.get(serverGroup).addServer(serverStatusData);
} }
} }
@ -392,8 +401,9 @@ public class Repository
connection = DriverManager.getConnection(_connectionString, _userName, _password); connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = connection.prepareStatement(DELETE_SERVER_STATUS); preparedStatement = connection.prepareStatement(DELETE_SERVER_STATUS);
preparedStatement.setString(1, serverToKill.PrivateAddress + ":" + serverToKill.Port); preparedStatement.setString(1, serverToKill.PrivateAddress);
preparedStatement.setString(2, serverToKill.Name); preparedStatement.setString(2, serverToKill.Port + "");
preparedStatement.setString(3, serverToKill.Name);
preparedStatement.execute(); preparedStatement.execute();
} }
catch (Exception exception) catch (Exception exception)

View File

@ -85,24 +85,6 @@ public class ServerMonitor
System.out.println("[" + bestServer.Name + ":" + bestServer.Address + "] Adding " + serverGroup.Name + " Req Total: " + serverGroup.RequiredTotalServers + " Req Joinable: " + serverGroup.RequiredJoinableServers + " | Actual Total: " + groupStatus.getTotalServers() + " Actual Joinable: " + groupStatus.getJoinableCount()); System.out.println("[" + bestServer.Name + ":" + bestServer.Address + "] Adding " + serverGroup.Name + " Req Total: " + serverGroup.RequiredTotalServers + " Req Joinable: " + serverGroup.RequiredJoinableServers + " | Actual Total: " + groupStatus.getTotalServers() + " Actual Joinable: " + groupStatus.getJoinableCount());
/*
// Kill if any previous attempts stack up
ServerStatusData newServer = new ServerStatusData();
newServer.Address = bestServer.Address;
newServer.Name = serverGroup.Prefix + "-" + serverNum;
killServer(newServer, false);
// Delay between kill and start so we don't kill the new process
try
{
Thread.sleep(100);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
*/
startServer(bestServer, serverGroup, serverNum); startServer(bestServer, serverGroup, serverNum);
serversToAdd--; serversToAdd--;

View File

@ -30,7 +30,7 @@ public class GameGemManager implements Listener
{ {
ArcadeManager Manager; ArcadeManager Manager;
boolean DoubleGem = true; boolean DoubleGem = false;
public GameGemManager(ArcadeManager manager) public GameGemManager(ArcadeManager manager)
{ {