Remove VL logging for good

This commit is contained in:
samczsun 2016-12-22 22:25:18 -05:00
parent df5c53766c
commit 1bcbddee87
3 changed files with 7 additions and 223 deletions

View File

@ -203,16 +203,13 @@ public class AntiHack extends MiniPlugin
String finalMessage = "[GWEN] " + id;
_logger.saveMetadata(player, id, () ->
{
_logger.resetViolations(player, () ->
runAsync(() ->
{
runAsync(() ->
{
GwenBanNotification notification = new GwenBanNotification(_thisServer, player.getName(), player.getUniqueId().toString(), CheckManager.getCheckSimpleName(cause), id);
ServerCommandManager.getInstance().publishCommand(notification);
});
_punish.AddPunishment(coreClient.getName(), Category.Hacking, finalMessage, AntiHack.NAME, 3, true, -1, true, after);
GwenBanNotification notification = new GwenBanNotification(_thisServer, player.getName(), player.getUniqueId().toString(), CheckManager.getCheckSimpleName(cause), id);
ServerCommandManager.getInstance().publishCommand(notification);
});
_punish.AddPunishment(coreClient.getName(), Category.Hacking, finalMessage, AntiHack.NAME, 3, true, -1, true, after);
}, custom);
};

View File

@ -2,164 +2,24 @@ package mineplex.core.antihack.logging;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
import java.util.Optional;
import org.bukkit.plugin.java.JavaPlugin;
import com.mineplex.anticheat.checks.Check;
import com.mineplex.anticheat.checks.CheckManager;
import mineplex.core.antihack.ViolationLevels;
import mineplex.core.database.MinecraftRepository;
import mineplex.serverdata.database.DBPool;
import gnu.trove.map.TIntObjectMap;
public class AnticheatDatabase extends MinecraftRepository
{
/*
CREATE TABLE IF NOT EXISTS anticheat_vl_logs (accountId INT, checkId INT, maxViolations INT, totalAlerts INT, sinceLastBan INT, PRIMARY KEY(accountId, checkId));
CREATE TABLE IF NOT EXISTS anticheat_ban_metadata (id INT NOT NULL AUTO_INCREMENT, accountId INT, banId CHAR(10) NOT NULL, data MEDIUMTEXT NOT NULL, PRIMARY KEY(id));
*/
private static final String INSERT_INTO_METADATA = "INSERT INTO anticheat_ban_metadata (accountId, banId, data) VALUES (?, ?, ?);";
private static final String UPDATE_VIOLATIONS = "INSERT INTO anticheat_vl_logs (accountId, checkId, "
+ "maxViolations, sinceLastBan, totalAlerts) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY"
+ " UPDATE maxViolations = VALUES(maxViolations), totalAlerts = VALUES(totalAlerts), sinceLastBan = VALUES(sinceLastBan);";
private static final String CLEAR_LAST_BAN_VIOLATIONS = "UPDATE anticheat_vl_logs SET sinceLastBan = 0 WHERE accountId = ?;";
private static final String GET_VLS = "SELECT checkId, maxViolations, sinceLastBan, totalAlerts FROM anticheat_vl_logs";
private static final String GET_VLS_BY_ACCOUNT_ID = GET_VLS + " WHERE accountId = ?";
private static final String GET_VLS_FOR_CHECK = GET_VLS + " WHERE checkId = ? AND accountId = ?";
public AnticheatDatabase(JavaPlugin plugin)
public AnticheatDatabase()
{
super(DBPool.getAccount());
}
/**
* Submit a set of user violation changes batch style.
*
* @param uploadQueue the {@link TIntObjectMap} describing the changes.
*/
public void saveViolationLevels(Map<Integer, ViolationLevels> uploadQueue)
{
/*try (Connection connection = getConnection())
{
PreparedStatement preparedStatement = connection.prepareStatement(UPDATE_VIOLATIONS);
uploadQueue.forEach((accountId, vls) ->
{
CheckManager.AVAILABLE_CHECKS.values().forEach(check ->
{
int checkId = CheckManager.getCheckId(check),
maxVls = vls.getMaxViolationsForCheck(check),
maxVlsSinceLastBan = vls.getLastBanViolationsForCheck(check),
totalAlerts = vls.getTotalAlertsForCheck(check);
// if neither value has been set don't store anything
if (maxVls < 0 && totalAlerts < 0 && maxVlsSinceLastBan < 0)
{
return;
}
maxVls = Math.max(maxVls, 0);
maxVlsSinceLastBan = Math.max(maxVlsSinceLastBan, 0);
totalAlerts = Math.max(totalAlerts, 0);
try
{
preparedStatement.setInt(1, accountId);
preparedStatement.setInt(2, checkId);
preparedStatement.setInt(3, maxVls);
preparedStatement.setInt(4, maxVlsSinceLastBan);
preparedStatement.setInt(5, totalAlerts);
preparedStatement.addBatch();
}
catch (SQLException e)
{
e.printStackTrace();
}
});
});
preparedStatement.executeBatch();
}
catch (SQLException ex)
{
ex.printStackTrace();
}*/
}
/**
* Attempts to retrieve violation levels for the given account id.
*
* @param accountId The account id;
* @return an {@link Optional} describing the user's violation levels, or an empty one if none
* are found.
* @throws SQLException On failing to connect to the database.
*/
public Optional<ViolationLevels> getViolationLevels(int accountId)
{
ViolationLevels levels = new ViolationLevels();
try (Connection connection = getConnection())
{
PreparedStatement statement = connection.prepareStatement(GET_VLS_BY_ACCOUNT_ID);
statement.setInt(1, accountId);
ResultSet result = statement.executeQuery();
while (result.next())
{
int checkId = result.getInt("checkId");
Class<? extends Check> checkType = CheckManager.getCheckById(checkId);
if (checkType == null)
{
System.err.println("Whoops. Unintended refactor?");
continue;
}
levels.updateMaxViolations(checkType, result.getInt("maxViolations"));
levels.updateMaxViolationsSinceLastBan(checkType, result.getInt("sinceLastBan"));
levels.setTotalAlerts(checkType, result.getInt("totalAlerts"));
}
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return Optional.of(levels);
}
public void clearLastBan(int accountId, Runnable after)
{
try (Connection connection = getConnection())
{
PreparedStatement statement = connection.prepareStatement(CLEAR_LAST_BAN_VIOLATIONS);
statement.setInt(1, accountId);
statement.executeUpdate();
}
catch (SQLException e)
{
e.printStackTrace();
}
finally
{
if (after != null)
after.run();
}
}
public void saveMetadata(int accountId, String id, String base64, Runnable after)
{
try (Connection connection = getConnection())
@ -181,16 +41,4 @@ public class AnticheatDatabase extends MinecraftRepository
after.run();
}
}
@Override
protected void initialize()
{
}
@Override
protected void update()
{
}
}

View File

@ -42,12 +42,8 @@ public class AntihackLogger extends MiniPlugin
{
public static final Gson GSON = new Gson();
private static final int PUSH_QUEUE_TIME_IN_SECONDS = 60;
private final CoreClientManager _clientManager = require(CoreClientManager.class);
private final Map<Integer, ViolationLevels> _violationLevels = new ConcurrentHashMap<>();
private final Map<String, AnticheatMetadata> _metadata = new HashMap<>();
private final AnticheatDatabase _db;
@ -56,9 +52,7 @@ public class AntihackLogger extends MiniPlugin
{
super("AnticheatPlugin");
_db = new AnticheatDatabase(getPlugin());
runSyncTimer(this::pushQueuedViolationChanges, 20, 20 * PUSH_QUEUE_TIME_IN_SECONDS);
_db = new AnticheatDatabase();
registerMetadata(new ServerInfoMetadata());
registerMetadata(new ViolationInfoMetadata());
@ -66,12 +60,6 @@ public class AntihackLogger extends MiniPlugin
registerMetadata(new PlayerInfoMetadata());
}
@Override
public void disable()
{
pushQueuedViolationChanges();
}
@EventHandler
public void addCommands()
{
@ -101,53 +89,9 @@ public class AntihackLogger extends MiniPlugin
}
}
private void pushQueuedViolationChanges()
{
Map<Integer, ViolationLevels> clone = new HashMap<>(_violationLevels);
runAsync(() -> _db.saveViolationLevels(clone));
}
@EventHandler
public void onCheckFail(PlayerViolationEvent event)
{
ViolationLevels playerVls = _violationLevels.get(_clientManager.getAccountId(event.getPlayer()));
Class<? extends Check> check = event.getCheckClass();
playerVls.updateMaxViolations(check, event.getViolations());
playerVls.updateMaxViolationsSinceLastBan(check, event.getViolations());
playerVls.incrementAlerts(check);
}
/*@EventHandler
public void onLoad(PlayerLoginEvent event)
{
runAsync(() ->
{
int accountId = _clientManager.getAccountId(event.getPlayer());
_db.getViolationLevels(accountId)
.ifPresent(vls ->
{
_violationLevels.put(accountId, vls);
});
});
}*/
@EventHandler
public void onQuit(PlayerQuitEvent event)
{
Player player = event.getPlayer();
int accountId =_clientManager.getAccountId(event.getPlayer());
ViolationLevels levels = _violationLevels.get(accountId);
if (levels != null)
{
Map<Integer, ViolationLevels> clone = new HashMap<>();
clone.put(accountId, levels);
runAsync(() -> _db.saveViolationLevels(clone));
}
_metadata.values().forEach(metadata -> metadata.remove(event.getPlayer().getUniqueId()));
}
@ -205,9 +149,4 @@ public class AntihackLogger extends MiniPlugin
throw new IllegalArgumentException("Attempting to register: " + metadata.getId());
}
}
public void resetViolations(Player player, Runnable after)
{
//_db.clearLastBan(_clientManager.getAccountId(player), after);
}
}