Merge branch 'master' of ssh://dev.mineplex.com:7999/min/mineplex

This commit is contained in:
Chiss 2013-10-16 12:24:02 +11:00
commit 9cdcbed086
4 changed files with 149 additions and 36 deletions

Binary file not shown.

View File

@ -225,6 +225,7 @@ public class CoreClientManager implements Listener
}, name, rank, perm);
}
/*
@EventHandler
public void cleanGlitchedClients(UpdateEvent event)
{
@ -233,8 +234,10 @@ public class CoreClientManager implements Listener
for (Iterator<Entry<String, CoreClient>> clientIterator = _clientList.entrySet().iterator(); clientIterator.hasNext();)
{
if (!clientIterator.next().getValue().GetPlayer().isOnline())
Player clientPlayer = clientIterator.next().getValue().GetPlayer();
if (clientPlayer == null || !clientPlayer.isOnline())
clientIterator.remove();
}
}
*/
}

View File

@ -15,7 +15,8 @@ public class Repository
private String _password = "y2D4atu3Pene2asw";
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 RETRIEVE_SERVER_STATUSES = "SELECT serverName, address, motd, players, maxPlayers FROM ServerStatus WHERE TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) > 10;";
private static String RETRIEVE_OLD_SERVER_STATUSES = "SELECT serverName, address, motd, players, maxPlayers FROM ServerStatus WHERE TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) > 10;";
private static String RETRIEVE_SERVER_STATUSES = "SELECT serverName, address, motd, players, maxPlayers FROM ServerStatus WHERE TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) <= 10;";
public void initialize()
{
@ -52,12 +53,75 @@ public class Repository
}
}
public List<ServerStatusData> retrieveServerStatuses()
public List<ServerStatusData> retrieveOldServerStatuses()
{
Connection connection = null;
ResultSet resultSet = null;
List<ServerStatusData> serverData = new ArrayList<ServerStatusData>();
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(RETRIEVE_OLD_SERVER_STATUSES);
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
{
ServerStatusData serverStatusData = new ServerStatusData();
serverStatusData.Name = resultSet.getString(1);
String addressPortString = resultSet.getString(2);
serverStatusData.Address = addressPortString.split(":")[0];
serverStatusData.Port = Integer.parseInt(addressPortString.split(":")[1]);
serverStatusData.Motd = resultSet.getString(3);
serverStatusData.Players = resultSet.getInt(4);
serverStatusData.MaxPlayers = resultSet.getInt(5);
serverData.add(serverStatusData);
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (resultSet != null)
{
try
{
resultSet.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try
{
connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
return serverData;
}
public List<GroupStatusData> retrieveGroupStatusData()
{
Connection connection = null;
ResultSet resultSet = null;
List<GroupStatusData> groupData = new ArrayList<GroupStatusData>();
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);

View File

@ -6,6 +6,7 @@ import java.io.InputStreamReader;
public class ServerMonitor
{
private static Repository _repository = new Repository();
private static int _count = 0;
public static void main (String args[])
{
@ -13,49 +14,94 @@ public class ServerMonitor
while (true)
{
for (ServerStatusData statusData : _repository.retrieveServerStatuses())
if (_count % 20 == 0)
{
String key = statusData.Address + " " + statusData.Name;
String cmd = "/home/mineplex/restartServer.sh";
Process process = null;
try
{
process = new ProcessBuilder(new String[] {"/bin/sh", "-x", cmd, statusData.Address, statusData.Name}).start();
process.waitFor();
BufferedReader reader=new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = reader.readLine();
while(line != null)
{
System.out.println(line);
line=reader.readLine();
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
if (process != null)
{
process.destroy();
}
}
System.out.println("Sent restart command to " + key + "");
for (ServerStatusData statusData : _repository.retrieveOldServerStatuses())
{
String key = statusData.Address + " " + statusData.Name;
String cmd = "/home/mineplex/restartServer.sh";
Process process = null;
try
{
process = new ProcessBuilder(new String[] {"/bin/sh", "-x", cmd, statusData.Address, statusData.Name}).start();
process.waitFor();
BufferedReader reader=new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = reader.readLine();
while(line != null)
{
System.out.println(line);
line=reader.readLine();
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
if (process != null)
{
process.destroy();
}
}
System.out.println("Sent restart command to " + key + "");
}
}
if (_count % 10 == 0)
{
HashMap<String, GroupStatusData>
for (ServerStatusData statusData : _repository.retrieveGroupStatusData())
{
String key = statusData.Address + " " + statusData.Name;
String cmd = "/home/mineplex/restartServer.sh";
Process process = null;
try
{
process = new ProcessBuilder(new String[] {"/bin/sh", "-x", cmd, statusData.Address, statusData.Name}).start();
process.waitFor();
BufferedReader reader=new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = reader.readLine();
while(line != null)
{
System.out.println(line);
line=reader.readLine();
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
if (process != null)
{
process.destroy();
}
}
System.out.println("Sent restart command to " + key + "");
}
}
try
{
Thread.sleep(15000);
Thread.sleep(1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
_count++;
_count %= 20;
}
}
}