Added Player version stat tracking.

Added server group stats.
This commit is contained in:
Jonathan Williams 2014-03-29 01:32:24 -04:00
parent aae40d3899
commit 6963f6bacf
5 changed files with 116 additions and 7 deletions

View File

@ -222,9 +222,9 @@
</jar>
<copy file="../bin/ServerMonitor.jar" todir="../../Testing/ServerMonitor/"/>
</target>
<target name ="ServerStatus" description="ServerStatus">
<jar jarfile="../bin/ServerStatus.jar">
<fileset dir="../Mineplex.ServerStatus/bin">
<target name ="ServerStatifier" description="ServerStatifier">
<jar jarfile="../bin/ServerStatifier.jar">
<fileset dir="../Mineplex.ServerStatifier/bin">
<include name="**/*.class"/>
</fileset>
@ -232,9 +232,9 @@
<manifest>
<attribute name="Main-Class"
value="mineplex.serverstatus.ServerStatus"/>
value="mineplex.serverstatifier.ServerStatifier"/>
</manifest>
</jar>
<copy file="../bin/ServerStatus.jar" todir="../../Testing/ServerStatus/"/>
<copy file="../bin/ServerStatifier.jar" todir="../../Testing/ServerStatifier/"/>
</target>
</project>
</project>

View File

@ -24,5 +24,6 @@ public class PlayerStats implements Listener
public void playerConnect(PostLoginEvent event)
{
_repository.addPlayer(event.getPlayer().getName());
_repository.addPlayerVersion(event.getPlayer().getName(), (event.getPlayer().getPendingConnection().getVersion() == 4 ? "1.7" : "1.6"));
}
}

View File

@ -16,6 +16,9 @@ public class PlayerStatsRepository
private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS DailyUnique (id INT NOT NULL AUTO_INCREMENT, day VARCHAR(100), playerName VARCHAR(20), PRIMARY KEY (id), UNIQUE KEY unique_player_per_day (day, playerName));";
private static String INSERT_PLAYER = "INSERT INTO DailyUnique (day, playerName) values(curdate(), ?) ON DUPLICATE KEY UPDATE playerName=playerName;";
private static String CREATE_VER_TABLE = "CREATE TABLE IF NOT EXISTS PlayerVersion (id INT NOT NULL AUTO_INCREMENT, playerName VARCHAR(20), version VARCHAR(40), PRIMARY KEY (id), UNIQUE KEY unique_player (playerName));";
private static String INSERT_VER_PLAYER = "INSERT INTO PlayerVersion (playerName, version) values(?, ?) ON DUPLICATE KEY UPDATE version=version;";
public void initialize()
{
PreparedStatement preparedStatement = null;
@ -28,6 +31,11 @@ public class PlayerStatsRepository
// Create table
preparedStatement = _connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute();
preparedStatement.close();
preparedStatement = _connection.prepareStatement(CREATE_VER_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
{
@ -101,4 +109,58 @@ public class PlayerStatsRepository
}
}
}
public boolean addPlayerVersion(String playerName, String version)
{
PreparedStatement preparedStatement = null;
try
{
if (_connection == null || _connection.isClosed())
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = _connection.prepareStatement(INSERT_VER_PLAYER, Statement.RETURN_GENERATED_KEYS);
preparedStatement.setString(1, playerName);
preparedStatement.setString(2, version);
int affectedRows = preparedStatement.executeUpdate();
if (affectedRows == 0)
{
throw new SQLException("Adding player version record failed, no rows affected.");
}
return true;
}
catch (Exception exception)
{
exception.printStackTrace();
try
{
Thread.sleep(10);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
return addPlayer(playerName);
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
}

View File

@ -15,10 +15,47 @@ public class GroupStatusData
public int MaxServerNumber;
public List<ServerStatusData> EmptyServers = new ArrayList<ServerStatusData>();
public List<ServerStatusData> KillServers = new ArrayList<ServerStatusData>();
public HashMap<Integer, ServerStatusData> Servers = new HashMap<Integer, ServerStatusData>();
public void addServer(ServerStatusData serverStatusData)
{
if (Servers.containsKey(Integer.parseInt(serverStatusData.Name.split("-")[1])))
{
ServerStatusData existingServer = Servers.get(Integer.parseInt(serverStatusData.Name.split("-")[1]));
int existingCount = existingServer.Players;
int newCount = serverStatusData.Players;
if (newCount == 0 || newCount < existingCount)
{
KillServers.add(serverStatusData);
return;
}
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 (existingServer.Players / existingServer.MaxPlayers < 10)
_joinableCount--;
}
else
{
_joinableCount--;
}
}
}
}
}
Players += serverStatusData.Players;
MaxPlayers += serverStatusData.MaxPlayers;

View File

@ -59,6 +59,15 @@ public class ServerMonitor
Collection<ServerGroupData> serverGroups = _repository.retrieveServerGroups();
HashMap<String, GroupStatusData> groupStatusList = _repository.retrieveGroupStatusData();
for (GroupStatusData groupStatus : groupStatusList.values())
{
for (ServerStatusData serverToKill : groupStatus.KillServers)
{
System.out.println("----DUPLICATE SERVER----> " + serverToKill.Address + ", " + serverToKill.Name);
killServer(serverToKill);
}
}
for (ServerGroupData serverGroup : serverGroups)
{
if (!groupStatusList.containsKey(serverGroup.Name))