Refactored AntiHack a bit to try and remove CCM

This commit is contained in:
Jonathan Williams 2014-12-29 07:07:05 -05:00
parent 97f57b655b
commit 419f33fcc3
5 changed files with 123 additions and 147 deletions

View File

@ -42,8 +42,6 @@ import mineplex.core.updater.event.UpdateEvent;
public class AntiHack extends MiniPlugin public class AntiHack extends MiniPlugin
{ {
private static Object _antiHackLock = new Object();
public static AntiHack Instance; public static AntiHack Instance;
private boolean _enabled = true; private boolean _enabled = true;
@ -115,11 +113,8 @@ public class AntiHack extends MiniPlugin
if (!_enabled) if (!_enabled)
return; return;
synchronized (_antiHackLock)
{
_lastMoveEvent.put(event.getPlayer(), System.currentTimeMillis()); _lastMoveEvent.put(event.getPlayer(), System.currentTimeMillis());
} }
}
@EventHandler @EventHandler
public void playerTeleport(PlayerTeleportEvent event) public void playerTeleport(PlayerTeleportEvent event)
@ -127,11 +122,8 @@ public class AntiHack extends MiniPlugin
if (!_enabled) if (!_enabled)
return; return;
synchronized (_antiHackLock)
{
setIgnore(event.getPlayer(), 2000); setIgnore(event.getPlayer(), 2000);
} }
}
@EventHandler @EventHandler
public void playerVelocity(PlayerVelocityEvent event) public void playerVelocity(PlayerVelocityEvent event)
@ -139,11 +131,8 @@ public class AntiHack extends MiniPlugin
if (!_enabled) if (!_enabled)
return; return;
synchronized (_antiHackLock)
{
_velocityEvent.add(event.getPlayer()); _velocityEvent.add(event.getPlayer());
} }
}
@EventHandler @EventHandler
public void playerQuit(PlayerQuitEvent event) public void playerQuit(PlayerQuitEvent event)
@ -151,7 +140,7 @@ public class AntiHack extends MiniPlugin
if (!_enabled) if (!_enabled)
return; return;
ResetAll(event.getPlayer()); resetAll(event.getPlayer());
} }
@EventHandler @EventHandler
@ -162,8 +151,6 @@ public class AntiHack extends MiniPlugin
Player player = event.getPlayer(); Player player = event.getPlayer();
synchronized (_antiHackLock)
{
if (_velocityEvent.remove(player)) if (_velocityEvent.remove(player))
{ {
setIgnore(player, 2000); setIgnore(player, 2000);
@ -180,7 +167,6 @@ public class AntiHack extends MiniPlugin
} }
} }
} }
}
public void setIgnore(Player player, long time) public void setIgnore(Player player, long time)
{ {
@ -188,8 +174,6 @@ public class AntiHack extends MiniPlugin
for (Detector detector : _movementDetectors) for (Detector detector : _movementDetectors)
detector.Reset(player); detector.Reset(player);
synchronized (_antiHackLock)
{
//Already ignoring for a longer period //Already ignoring for a longer period
if (_ignore.containsKey(player) && _ignore.get(player) > System.currentTimeMillis() + time) if (_ignore.containsKey(player) && _ignore.get(player) > System.currentTimeMillis() + time)
return; return;
@ -197,7 +181,6 @@ public class AntiHack extends MiniPlugin
//Add Ignore //Add Ignore
_ignore.put(player, System.currentTimeMillis() + time); _ignore.put(player, System.currentTimeMillis() + time);
} }
}
public boolean isValid(Player player, boolean groundValid) public boolean isValid(Player player, boolean groundValid)
{ {
@ -246,8 +229,6 @@ public class AntiHack extends MiniPlugin
System.out.println(C.cRed + C.Bold + player.getName() + " suspected for " + type + "."); System.out.println(C.cRed + C.Bold + player.getName() + " suspected for " + type + ".");
synchronized (_antiHackLock)
{
//Add Offense //Add Offense
if (!_offense.containsKey(player)) if (!_offense.containsKey(player))
_offense.put(player, new HashMap<String, ArrayList<Long>>()); _offense.put(player, new HashMap<String, ArrayList<Long>>());
@ -284,7 +265,6 @@ public class AntiHack extends MiniPlugin
// Print (Debug) // Print (Debug)
System.out.println("[Offense] #" + total + ": "+ player.getName() + " received suspicion for " + type + "."); System.out.println("[Offense] #" + total + ": "+ player.getName() + " received suspicion for " + type + ".");
} }
}
@EventHandler @EventHandler
public void generateReports(UpdateEvent event) public void generateReports(UpdateEvent event)
@ -295,19 +275,18 @@ public class AntiHack extends MiniPlugin
if (event.getType() != UpdateType.SEC) if (event.getType() != UpdateType.SEC)
return; return;
synchronized (_antiHackLock) for (Iterator<Entry<Player, HashMap<String, ArrayList<Long>>>> playerIterator = _offense.entrySet().iterator(); playerIterator.hasNext();)
{ {
for (Iterator<Player> playerIterator = _offense.keySet().iterator(); playerIterator.hasNext();) Entry<Player, HashMap<String, ArrayList<Long>>> entry = playerIterator.next();
{ Player player = entry.getKey();
Player player = playerIterator.next();
String out = ""; String out = "";
int total = 0; int total = 0;
for (String type : _offense.get(player).keySet()) for (String type : entry.getValue().keySet())
{ {
//Remove Old Offenses //Remove Old Offenses
Iterator<Long> offenseIterator = _offense.get(player).get(type).iterator(); Iterator<Long> offenseIterator = entry.getValue().get(type).iterator();
while (offenseIterator.hasNext()) while (offenseIterator.hasNext())
{ {
long time = offenseIterator.next(); long time = offenseIterator.next();
@ -317,7 +296,7 @@ public class AntiHack extends MiniPlugin
} }
//Count //Count
int count = _offense.get(player).get(type).size(); int count = entry.getValue().get(type).size();
total += count; total += count;
out += count + " " + type + ", "; out += count + " " + type + ", ";
@ -326,17 +305,22 @@ public class AntiHack extends MiniPlugin
if (out.length() > 0) if (out.length() > 0)
out = out.substring(0, out.length() - 2); out = out.substring(0, out.length() - 2);
String severity; String severity = "Low";
if (total > (_strict ? 6 : 18)) severity = "Extreme";
else if (total > (_strict ? 4 : 12)) severity = "High"; if (total > (_strict ? 6 : 18))
else if (total > (_strict ? 2 : 6)) severity = "Medium"; severity = "Extreme";
else severity = "Low"; else if (total > (_strict ? 4 : 12))
severity = "High";
else if (total > (_strict ? 2 : 6))
severity = "Medium";
//Send Report //Send Report
sendReport(player, out, severity); sendReport(player, out, severity);
if (severity.equalsIgnoreCase("Extreme")) if (severity.equalsIgnoreCase("Extreme"))
{
playerIterator.remove(); playerIterator.remove();
resetAll(player, false);
} }
} }
} }
@ -345,8 +329,6 @@ public class AntiHack extends MiniPlugin
{ {
if (severity.equals("Extreme")) if (severity.equals("Extreme"))
{ {
ResetAll(player, false);
//Staff //Staff
boolean handled = false; boolean handled = false;
for (Player staff : UtilServer.getPlayers()) for (Player staff : UtilServer.getPlayers())
@ -414,20 +396,18 @@ public class AntiHack extends MiniPlugin
} }
} }
private void Reset() private void reset()
{ {
for (Player player : UtilServer.getPlayers()) for (Player player : UtilServer.getPlayers())
ResetAll(player); resetAll(player);
} }
private void ResetAll(Player player) private void resetAll(Player player)
{ {
ResetAll(player, true); resetAll(player, true);
} }
private void ResetAll(Player player, boolean removeOffenses) private void resetAll(Player player, boolean removeOffenses)
{
synchronized (_antiHackLock)
{ {
_ignore.remove(player); _ignore.remove(player);
_velocityEvent.remove(player); _velocityEvent.remove(player);
@ -442,7 +422,6 @@ public class AntiHack extends MiniPlugin
for (Detector detector : _combatDetectors) for (Detector detector : _combatDetectors)
detector.Reset(player); detector.Reset(player);
} }
}
@EventHandler @EventHandler
public void cleanupPlayers(UpdateEvent event) public void cleanupPlayers(UpdateEvent event)
@ -453,8 +432,6 @@ public class AntiHack extends MiniPlugin
if (event.getType() != UpdateType.SLOW) if (event.getType() != UpdateType.SLOW)
return; return;
synchronized (_antiHackLock)
{
for (Iterator<Entry<Player, Long>> playerIterator = _ignore.entrySet().iterator(); playerIterator.hasNext();) for (Iterator<Entry<Player, Long>> playerIterator = _ignore.entrySet().iterator(); playerIterator.hasNext();)
{ {
Player player = playerIterator.next().getKey(); Player player = playerIterator.next().getKey();
@ -476,15 +453,14 @@ public class AntiHack extends MiniPlugin
} }
} }
} }
}
public void SetEnabled(boolean b) public void setEnabled(boolean b)
{ {
_enabled = b; _enabled = b;
System.out.println("MAC Enabled: " + b); System.out.println("MAC Enabled: " + b);
} }
public boolean IsEnabled() public boolean isEnabled()
{ {
return _enabled; return _enabled;
} }
@ -493,7 +469,7 @@ public class AntiHack extends MiniPlugin
{ {
_strict = strict; _strict = strict;
Reset(); reset();
System.out.println("MAC Strict: " + strict); System.out.println("MAC Strict: " + strict);
} }

View File

@ -37,7 +37,7 @@ public class Fly extends MiniPlugin implements Detector
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void updateFlyhack(PlayerMoveEvent event) public void updateFlyhack(PlayerMoveEvent event)
{ {
if (!Host.IsEnabled()) if (!Host.isEnabled())
return; return;
Player player = event.getPlayer(); Player player = event.getPlayer();

View File

@ -32,7 +32,7 @@ public class Idle extends MiniPlugin implements Detector
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void updateFlyhack(PlayerMoveEvent event) public void updateFlyhack(PlayerMoveEvent event)
{ {
if (!Host.IsEnabled()) if (!Host.isEnabled())
return; return;
Player player = event.getPlayer(); Player player = event.getPlayer();
@ -43,7 +43,7 @@ public class Idle extends MiniPlugin implements Detector
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void updateFreeCam(UpdateEvent event) public void updateFreeCam(UpdateEvent event)
{ {
if (!Host.IsEnabled()) if (!Host.isEnabled())
return; return;
if (event.getType() != UpdateType.FAST) if (event.getType() != UpdateType.FAST)

View File

@ -38,7 +38,7 @@ public class Reach extends MiniPlugin implements Detector
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void recordMove(UpdateEvent event) public void recordMove(UpdateEvent event)
{ {
if (!Host.IsEnabled()) if (!Host.isEnabled())
return; return;
if (event.getType() != UpdateType.TICK) if (event.getType() != UpdateType.TICK)

View File

@ -33,7 +33,7 @@ public class Speed extends MiniPlugin implements Detector
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void updateSpeedhack(PlayerMoveEvent event) public void updateSpeedhack(PlayerMoveEvent event)
{ {
if (!Host.IsEnabled()) if (!Host.isEnabled())
return; return;
Player player = event.getPlayer(); Player player = event.getPlayer();