Added AntiHack to Arcade/Hub

Added AntiHack Offense uploading.
Fixed memory leaks in PreparedStatments
Added Ultra tag in hub chat.
This commit is contained in:
Jonathan Williams 2013-10-17 00:37:57 -07:00
parent d23f72567a
commit f88c202e07
12 changed files with 357 additions and 36 deletions

View File

@ -16,13 +16,14 @@ public class GlobalServerRepository
public void initialize()
{
Connection connection = null;
PreparedStatement preparedStatement = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table
PreparedStatement preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
@ -31,6 +32,18 @@ public class GlobalServerRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try

View File

@ -20,13 +20,14 @@ public class LobbyBalancerRepository
public void initialize()
{
Connection connection = null;
PreparedStatement preparedStatement = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table
PreparedStatement preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
@ -35,6 +36,18 @@ public class LobbyBalancerRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try
@ -53,13 +66,14 @@ public class LobbyBalancerRepository
{
Connection connection = null;
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
List<ServerStatusData> serverData = new ArrayList<ServerStatusData>();
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_STATUSES);
preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_STATUSES);
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
@ -84,6 +98,18 @@ public class LobbyBalancerRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null)
{
try

View File

@ -33,18 +33,21 @@ public class PlayerCountRepository
{
Connection connection = null;
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
PreparedStatement preparedStatementRetrieve = null;
PreparedStatement preparedStatementInsert = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table
PreparedStatement preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute();
// Retrieve id
PreparedStatement preparedStatementRetrieve = connection.prepareStatement(RETRIEVE_ID);
preparedStatementRetrieve = connection.prepareStatement(RETRIEVE_ID);
preparedStatementRetrieve.setString(1, _address);
resultSet = preparedStatementRetrieve.executeQuery();
@ -56,7 +59,7 @@ public class PlayerCountRepository
// Insert if not there
if (_id == -1)
{
PreparedStatement preparedStatementInsert = connection.prepareStatement(INSERT_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatementInsert = connection.prepareStatement(INSERT_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatementInsert.setString(1, _address);
preparedStatementInsert.setInt(2, 0);
@ -86,6 +89,42 @@ public class PlayerCountRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (preparedStatementRetrieve != null)
{
try
{
preparedStatementRetrieve.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (preparedStatementInsert != null)
{
try
{
preparedStatementInsert.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null)
{
try
@ -115,12 +154,13 @@ public class PlayerCountRepository
public boolean updatePlayerCountInDatabase(int players)
{
Connection connection = null;
PreparedStatement preparedStatement = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(UPDATE_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatement = connection.prepareStatement(UPDATE_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatement.setInt(1, players);
preparedStatement.setInt(2, _maxPlayers);
@ -144,6 +184,18 @@ public class PlayerCountRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try
@ -163,12 +215,13 @@ public class PlayerCountRepository
Connection connection = null;
PlayerTotalData playerData = new PlayerTotalData();
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(RETRIEVE_PLAYER_COUNT);
preparedStatement = connection.prepareStatement(RETRIEVE_PLAYER_COUNT);
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
@ -184,6 +237,18 @@ public class PlayerCountRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null)
{
try

View File

@ -21,13 +21,14 @@ public class PlayerTrackerRepository
public void initialize()
{
Connection connection = null;
PreparedStatement preparedStatement = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table
PreparedStatement preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
@ -36,6 +37,18 @@ public class PlayerTrackerRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try
@ -53,12 +66,13 @@ public class PlayerTrackerRepository
public boolean updatePlayerServer(String name, String server)
{
Connection connection = null;
PreparedStatement preparedStatement = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(UPDATE_PLAYER_SERVER);
preparedStatement = connection.prepareStatement(UPDATE_PLAYER_SERVER);
preparedStatement.setString(1, server);
preparedStatement.setString(2, name);
@ -89,6 +103,18 @@ public class PlayerTrackerRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try
@ -107,12 +133,13 @@ public class PlayerTrackerRepository
{
Connection connection = null;
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(RETRIEVE_PLAYER_SERVER);
preparedStatement = connection.prepareStatement(RETRIEVE_PLAYER_SERVER);
preparedStatement.setString(1, name);
resultSet = preparedStatement.executeQuery();
@ -127,6 +154,18 @@ public class PlayerTrackerRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null)
{
try
@ -158,12 +197,13 @@ public class PlayerTrackerRepository
public boolean removePlayer(String name)
{
Connection connection = null;
PreparedStatement preparedStatement = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(DELETE_PLAYER);
preparedStatement = connection.prepareStatement(DELETE_PLAYER);
preparedStatement.setString(1, name);
@ -183,6 +223,18 @@ public class PlayerTrackerRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try

View File

@ -30,6 +30,9 @@ import org.bukkit.util.Vector;
public class AntiHack extends MiniPlugin
{
public static AntiHack Instance;
private static Object _offensesSynch = new Object();
private AntiHackRepository _repository;
//Record Offesnes
private HashMap<Player, HashMap<String, Integer>> _offenses = new HashMap<Player, HashMap<String, Integer>>();
@ -58,6 +61,9 @@ public class AntiHack extends MiniPlugin
protected AntiHack(JavaPlugin plugin)
{
super("AntiHack", plugin);
_repository = new AntiHackRepository(this, plugin.getConfig().getString("serverstatus.name"));
_repository.initialize();
}
public static void Initialize(JavaPlugin plugin)
@ -135,7 +141,8 @@ public class AntiHack extends MiniPlugin
if (!UtilTime.elapsed(_lastMove.get(player), _freecamTime))
continue;
player.kickPlayer(C.cGold + "Mineplex " + C.cRed + "Anti-Hack " + C.cWhite + "Kicked for Lagging / Free Cam.");
//player.kickPlayer(C.cGold + "Mineplex " + C.cRed + "Anti-Hack " + C.cWhite + "Kicked for Lagging / Free Cam.");
AddOffense(player, "Free Cam / Lag / Float");
}
}
@ -162,6 +169,25 @@ public class AntiHack extends MiniPlugin
UpdateSpeed(player, event);
}
public HashMap<Player, HashMap<String, Integer>> getOffenses()
{
return _offenses;
}
public Object getOffensesSynch()
{
return _offensesSynch;
}
@EventHandler
public void updateDatabase(UpdateEvent event)
{
if (event.getType() != UpdateType.SLOWER)
return;
_repository.saveOffenses();
}
private void UpdateFloat(Player player)
{
int count = 0;
@ -276,6 +302,7 @@ public class AntiHack extends MiniPlugin
limit = 0.32;
for (PotionEffect effect : player.getActivePotionEffects())
{
if (effect.getType().equals(PotionEffectType.SPEED))
{
if (UtilEnt.isGrounded(player))
@ -283,6 +310,7 @@ public class AntiHack extends MiniPlugin
else
limit += 0.04 * (effect.getAmplifier() + 1);
}
}
//Check
if (offset > limit && !UtilTime.elapsed(_speedTicks.get(player).getValue(), 200))//Counters Lag
@ -305,6 +333,8 @@ public class AntiHack extends MiniPlugin
}
private void AddOffense(Player player, String type)
{
synchronized (getOffensesSynch())
{
if (!_offenses.containsKey(player))
_offenses.put(player, new HashMap<String, Integer>());
@ -314,6 +344,7 @@ public class AntiHack extends MiniPlugin
previous = _offenses.get(player).get(type);
_offenses.get(player).put(type, previous + 1);
}
//Print (Debug)
System.out.println("[Offense] " + player.getName() + " received offense for " + type + ".");
@ -337,6 +368,10 @@ public class AntiHack extends MiniPlugin
_ignore.remove(player);
_ignoreStart.remove(player);
synchronized (getOffensesSynch())
{
_offenses.remove(player);
}
}
}

View File

@ -42,18 +42,21 @@ public class ServerStatusRepository
{
Connection connection = null;
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
PreparedStatement preparedStatementRetrieve = null;
PreparedStatement preparedStatementInsert = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table
PreparedStatement preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute();
// Retrieve id
PreparedStatement preparedStatementRetrieve = connection.prepareStatement(RETRIEVE_ID);
preparedStatementRetrieve = connection.prepareStatement(RETRIEVE_ID);
preparedStatementRetrieve.setString(1, _address);
resultSet = preparedStatementRetrieve.executeQuery();
@ -65,7 +68,7 @@ public class ServerStatusRepository
// Insert if not there
if (_id == -1)
{
PreparedStatement preparedStatementInsert = connection.prepareStatement(INSERT_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatementInsert = connection.prepareStatement(INSERT_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatementInsert.setString(1, _serverName);
preparedStatementInsert.setString(2, _serverGroup);
@ -99,6 +102,42 @@ public class ServerStatusRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (preparedStatementRetrieve != null)
{
try
{
preparedStatementRetrieve.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (preparedStatementInsert != null)
{
try
{
preparedStatementInsert.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null)
{
try
@ -128,12 +167,13 @@ public class ServerStatusRepository
public boolean updatePlayerCountInDatabase(String motd, int players, int maxPlayers, int tps)
{
Connection connection = null;
PreparedStatement preparedStatement = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(UPDATE_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatement = connection.prepareStatement(UPDATE_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatement.setString(1, _serverName);
preparedStatement.setString(2, _serverGroup);
@ -161,6 +201,18 @@ public class ServerStatusRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try
@ -179,13 +231,14 @@ public class ServerStatusRepository
{
Connection connection = null;
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
List<ServerStatusData> serverData = new ArrayList<ServerStatusData>();
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_STATUSES);
preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_STATUSES);
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
@ -206,6 +259,18 @@ public class ServerStatusRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null)
{
try

View File

@ -2,6 +2,7 @@ package mineplex.hub;
import me.chiss.Core.MemoryFix.MemoryFix;
import mineplex.core.account.CoreClientManager;
import mineplex.core.antihack.AntiHack;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.chat.Chat;
import mineplex.core.command.CommandCenter;
@ -66,6 +67,7 @@ public class Hub extends JavaPlugin implements INautilusPlugin, IRelation
CommandCenter.Initialize(this, clientManager);
ItemStackFactory.Initialize(this, false);
Recharge.Initialize(this);
AntiHack.Initialize(this);
DonationManager donationManager = new DonationManager(this, GetWebServerAddress());

View File

@ -319,9 +319,15 @@ public class HubManager extends MiniClientPlugin<HubClient>
Rank rank = GetClients().Get(player).GetRank();
boolean ownsUltra = _donationManager.Get(player.getName()).OwnsUltraPackage();
//Rank Prefix
String rankStr = "";
if (rank != Rank.ALL)
rankStr = rank.Color + C.Bold + GetClients().Get(player).GetRank().Name.toUpperCase() + " ";
rankStr = rank.Color + C.Bold + rank.Name.toUpperCase() + " ";
if (ownsUltra && !rank.Has(Rank.ULTRA))
rankStr = Rank.ULTRA.Color + C.Bold + Rank.ULTRA.Name.toUpperCase() + " ";
//Party Chat
if (event.getMessage().charAt(0) == '@')

View File

@ -0,0 +1,6 @@
package mineplex.servermonitor;
public class DynamicMonitor
{
}

View File

@ -0,0 +1,13 @@
package mineplex.servermonitor;
import java.util.ArrayList;
import java.util.List;
public class GroupStatusData
{
public String Name;
public int Players;
public int MaxPlayers;
public List<ServerStatusData> Servers = new ArrayList<ServerStatusData>();
}

View File

@ -20,8 +20,8 @@ public class Repository
public void initialize()
{
Connection connection = null;
PreparedStatement preparedStatement = null;
try
{
@ -30,7 +30,7 @@ public class Repository
connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table
PreparedStatement preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
@ -39,6 +39,18 @@ public class Repository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try
@ -57,13 +69,14 @@ public class Repository
{
Connection connection = null;
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
List<ServerStatusData> serverData = new ArrayList<ServerStatusData>();
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(RETRIEVE_OLD_SERVER_STATUSES);
preparedStatement = connection.prepareStatement(RETRIEVE_OLD_SERVER_STATUSES);
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
@ -88,6 +101,18 @@ public class Repository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null)
{
try
@ -120,13 +145,14 @@ public class Repository
{
Connection connection = null;
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
List<GroupStatusData> groupData = new ArrayList<GroupStatusData>();
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_STATUSES);
preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_STATUSES);
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
@ -151,6 +177,18 @@ public class Repository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null)
{
try