Refactored AntiHack a bit to try and remove CCM
This commit is contained in:
parent
97f57b655b
commit
419f33fcc3
@ -42,8 +42,6 @@ import mineplex.core.updater.event.UpdateEvent;
|
||||
|
||||
public class AntiHack extends MiniPlugin
|
||||
{
|
||||
private static Object _antiHackLock = new Object();
|
||||
|
||||
public static AntiHack Instance;
|
||||
|
||||
private boolean _enabled = true;
|
||||
@ -115,10 +113,7 @@ public class AntiHack extends MiniPlugin
|
||||
if (!_enabled)
|
||||
return;
|
||||
|
||||
synchronized (_antiHackLock)
|
||||
{
|
||||
_lastMoveEvent.put(event.getPlayer(), System.currentTimeMillis());
|
||||
}
|
||||
_lastMoveEvent.put(event.getPlayer(), System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -127,10 +122,7 @@ public class AntiHack extends MiniPlugin
|
||||
if (!_enabled)
|
||||
return;
|
||||
|
||||
synchronized (_antiHackLock)
|
||||
{
|
||||
setIgnore(event.getPlayer(), 2000);
|
||||
}
|
||||
setIgnore(event.getPlayer(), 2000);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -139,10 +131,7 @@ public class AntiHack extends MiniPlugin
|
||||
if (!_enabled)
|
||||
return;
|
||||
|
||||
synchronized (_antiHackLock)
|
||||
{
|
||||
_velocityEvent.add(event.getPlayer());
|
||||
}
|
||||
_velocityEvent.add(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -151,7 +140,7 @@ public class AntiHack extends MiniPlugin
|
||||
if (!_enabled)
|
||||
return;
|
||||
|
||||
ResetAll(event.getPlayer());
|
||||
resetAll(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -162,22 +151,19 @@ public class AntiHack extends MiniPlugin
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
synchronized (_antiHackLock)
|
||||
if (_velocityEvent.remove(player))
|
||||
{
|
||||
if (_velocityEvent.remove(player))
|
||||
{
|
||||
setIgnore(player, 2000);
|
||||
}
|
||||
setIgnore(player, 2000);
|
||||
}
|
||||
|
||||
//Initial Move (or Lag) Ignore
|
||||
if (_lastMoveEvent.containsKey(player))
|
||||
{
|
||||
long timeBetweenPackets = System.currentTimeMillis() - _lastMoveEvent.get(player);
|
||||
//Initial Move (or Lag) Ignore
|
||||
if (_lastMoveEvent.containsKey(player))
|
||||
{
|
||||
long timeBetweenPackets = System.currentTimeMillis() - _lastMoveEvent.get(player);
|
||||
|
||||
if (timeBetweenPackets > 500)
|
||||
{
|
||||
setIgnore(player, Math.min(4000, timeBetweenPackets));
|
||||
}
|
||||
if (timeBetweenPackets > 500)
|
||||
{
|
||||
setIgnore(player, Math.min(4000, timeBetweenPackets));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -188,15 +174,12 @@ public class AntiHack extends MiniPlugin
|
||||
for (Detector detector : _movementDetectors)
|
||||
detector.Reset(player);
|
||||
|
||||
synchronized (_antiHackLock)
|
||||
{
|
||||
//Already ignoring for a longer period
|
||||
if (_ignore.containsKey(player) && _ignore.get(player) > System.currentTimeMillis() + time)
|
||||
return;
|
||||
//Already ignoring for a longer period
|
||||
if (_ignore.containsKey(player) && _ignore.get(player) > System.currentTimeMillis() + time)
|
||||
return;
|
||||
|
||||
//Add Ignore
|
||||
_ignore.put(player, System.currentTimeMillis() + time);
|
||||
}
|
||||
//Add Ignore
|
||||
_ignore.put(player, System.currentTimeMillis() + time);
|
||||
}
|
||||
|
||||
public boolean isValid(Player player, boolean groundValid)
|
||||
@ -246,44 +229,41 @@ public class AntiHack extends MiniPlugin
|
||||
|
||||
System.out.println(C.cRed + C.Bold + player.getName() + " suspected for " + type + ".");
|
||||
|
||||
synchronized (_antiHackLock)
|
||||
//Add Offense
|
||||
if (!_offense.containsKey(player))
|
||||
_offense.put(player, new HashMap<String, ArrayList<Long>>());
|
||||
|
||||
if (!_offense.get(player).containsKey(type))
|
||||
_offense.get(player).put(type, new ArrayList<Long>());
|
||||
|
||||
_offense.get(player).get(type).add(System.currentTimeMillis());
|
||||
|
||||
//Cull & Count
|
||||
int total = 0;
|
||||
for (String curType : _offense.get(player).keySet())
|
||||
{
|
||||
//Add Offense
|
||||
if (!_offense.containsKey(player))
|
||||
_offense.put(player, new HashMap<String, ArrayList<Long>>());
|
||||
|
||||
if (!_offense.get(player).containsKey(type))
|
||||
_offense.get(player).put(type, new ArrayList<Long>());
|
||||
|
||||
_offense.get(player).get(type).add(System.currentTimeMillis());
|
||||
|
||||
//Cull & Count
|
||||
int total = 0;
|
||||
for (String curType : _offense.get(player).keySet())
|
||||
//Remove Old Offenses
|
||||
Iterator<Long> offenseIterator = _offense.get(player).get(curType).iterator();
|
||||
while (offenseIterator.hasNext())
|
||||
{
|
||||
//Remove Old Offenses
|
||||
Iterator<Long> offenseIterator = _offense.get(player).get(curType).iterator();
|
||||
while (offenseIterator.hasNext())
|
||||
{
|
||||
if (UtilTime.elapsed(offenseIterator.next(), KeepOffensesFor))
|
||||
offenseIterator.remove();
|
||||
}
|
||||
|
||||
//Count
|
||||
total += _offense.get(player).get(curType).size();
|
||||
if (UtilTime.elapsed(offenseIterator.next(), KeepOffensesFor))
|
||||
offenseIterator.remove();
|
||||
}
|
||||
|
||||
|
||||
//Inform
|
||||
for (Player admin : UtilServer.getPlayers())
|
||||
if (_clientManager.Get(admin).GetRank().Has(Rank.MODERATOR) && _preferences.Get(admin).ShowMacReports)
|
||||
{
|
||||
UtilPlayer.message(admin, "#" + total + ": " + C.cRed + C.Bold + player.getName() + " suspected for " + type + ".");
|
||||
}
|
||||
|
||||
// Print (Debug)
|
||||
System.out.println("[Offense] #" + total + ": "+ player.getName() + " received suspicion for " + type + ".");
|
||||
//Count
|
||||
total += _offense.get(player).get(curType).size();
|
||||
}
|
||||
|
||||
|
||||
//Inform
|
||||
for (Player admin : UtilServer.getPlayers())
|
||||
if (_clientManager.Get(admin).GetRank().Has(Rank.MODERATOR) && _preferences.Get(admin).ShowMacReports)
|
||||
{
|
||||
UtilPlayer.message(admin, "#" + total + ": " + C.cRed + C.Bold + player.getName() + " suspected for " + type + ".");
|
||||
}
|
||||
|
||||
// Print (Debug)
|
||||
System.out.println("[Offense] #" + total + ": "+ player.getName() + " received suspicion for " + type + ".");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -295,48 +275,52 @@ public class AntiHack extends MiniPlugin
|
||||
if (event.getType() != UpdateType.SEC)
|
||||
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();
|
||||
|
||||
String out = "";
|
||||
int total = 0;
|
||||
|
||||
for (String type : entry.getValue().keySet())
|
||||
{
|
||||
Player player = playerIterator.next();
|
||||
|
||||
String out = "";
|
||||
int total = 0;
|
||||
|
||||
for (String type : _offense.get(player).keySet())
|
||||
//Remove Old Offenses
|
||||
Iterator<Long> offenseIterator = entry.getValue().get(type).iterator();
|
||||
while (offenseIterator.hasNext())
|
||||
{
|
||||
//Remove Old Offenses
|
||||
Iterator<Long> offenseIterator = _offense.get(player).get(type).iterator();
|
||||
while (offenseIterator.hasNext())
|
||||
{
|
||||
long time = offenseIterator.next();
|
||||
long time = offenseIterator.next();
|
||||
|
||||
if (UtilTime.elapsed(time, KeepOffensesFor))
|
||||
offenseIterator.remove();
|
||||
}
|
||||
|
||||
//Count
|
||||
int count = _offense.get(player).get(type).size();
|
||||
total += count;
|
||||
|
||||
out += count + " " + type + ", ";
|
||||
if (UtilTime.elapsed(time, KeepOffensesFor))
|
||||
offenseIterator.remove();
|
||||
}
|
||||
|
||||
if (out.length() > 0)
|
||||
out = out.substring(0, out.length() - 2);
|
||||
//Count
|
||||
int count = entry.getValue().get(type).size();
|
||||
total += count;
|
||||
|
||||
String severity;
|
||||
if (total > (_strict ? 6 : 18)) severity = "Extreme";
|
||||
else if (total > (_strict ? 4 : 12)) severity = "High";
|
||||
else if (total > (_strict ? 2 : 6)) severity = "Medium";
|
||||
else severity = "Low";
|
||||
out += count + " " + type + ", ";
|
||||
}
|
||||
|
||||
//Send Report
|
||||
sendReport(player, out, severity);
|
||||
|
||||
if (severity.equalsIgnoreCase("Extreme"))
|
||||
playerIterator.remove();
|
||||
if (out.length() > 0)
|
||||
out = out.substring(0, out.length() - 2);
|
||||
|
||||
String severity = "Low";
|
||||
|
||||
if (total > (_strict ? 6 : 18))
|
||||
severity = "Extreme";
|
||||
else if (total > (_strict ? 4 : 12))
|
||||
severity = "High";
|
||||
else if (total > (_strict ? 2 : 6))
|
||||
severity = "Medium";
|
||||
|
||||
//Send Report
|
||||
sendReport(player, out, severity);
|
||||
|
||||
if (severity.equalsIgnoreCase("Extreme"))
|
||||
{
|
||||
playerIterator.remove();
|
||||
resetAll(player, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -345,8 +329,6 @@ public class AntiHack extends MiniPlugin
|
||||
{
|
||||
if (severity.equals("Extreme"))
|
||||
{
|
||||
ResetAll(player, false);
|
||||
|
||||
//Staff
|
||||
boolean handled = false;
|
||||
for (Player staff : UtilServer.getPlayers())
|
||||
@ -414,34 +396,31 @@ public class AntiHack extends MiniPlugin
|
||||
}
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
private void reset()
|
||||
{
|
||||
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);
|
||||
_velocityEvent.remove(player);
|
||||
_lastMoveEvent.remove(player);
|
||||
_ignore.remove(player);
|
||||
_velocityEvent.remove(player);
|
||||
_lastMoveEvent.remove(player);
|
||||
|
||||
if (removeOffenses)
|
||||
_offense.remove(player);
|
||||
if (removeOffenses)
|
||||
_offense.remove(player);
|
||||
|
||||
for (Detector detector : _movementDetectors)
|
||||
detector.Reset(player);
|
||||
|
||||
for (Detector detector : _combatDetectors)
|
||||
detector.Reset(player);
|
||||
}
|
||||
for (Detector detector : _movementDetectors)
|
||||
detector.Reset(player);
|
||||
|
||||
for (Detector detector : _combatDetectors)
|
||||
detector.Reset(player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -453,38 +432,35 @@ public class AntiHack extends MiniPlugin
|
||||
if (event.getType() != UpdateType.SLOW)
|
||||
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();
|
||||
|
||||
if (!player.isOnline() || player.isDead() || !player.isValid())
|
||||
{
|
||||
playerIterator.remove();
|
||||
if (!player.isOnline() || player.isDead() || !player.isValid())
|
||||
{
|
||||
playerIterator.remove();
|
||||
|
||||
_velocityEvent.remove(player);
|
||||
_lastMoveEvent.remove(player);
|
||||
_velocityEvent.remove(player);
|
||||
_lastMoveEvent.remove(player);
|
||||
|
||||
_offense.remove(player);
|
||||
_offense.remove(player);
|
||||
|
||||
for (Detector detector : _movementDetectors)
|
||||
detector.Reset(player);
|
||||
|
||||
for (Detector detector : _combatDetectors)
|
||||
detector.Reset(player);
|
||||
}
|
||||
for (Detector detector : _movementDetectors)
|
||||
detector.Reset(player);
|
||||
|
||||
for (Detector detector : _combatDetectors)
|
||||
detector.Reset(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetEnabled(boolean b)
|
||||
public void setEnabled(boolean b)
|
||||
{
|
||||
_enabled = b;
|
||||
System.out.println("MAC Enabled: " + b);
|
||||
}
|
||||
|
||||
public boolean IsEnabled()
|
||||
public boolean isEnabled()
|
||||
{
|
||||
return _enabled;
|
||||
}
|
||||
@ -493,7 +469,7 @@ public class AntiHack extends MiniPlugin
|
||||
{
|
||||
_strict = strict;
|
||||
|
||||
Reset();
|
||||
reset();
|
||||
|
||||
System.out.println("MAC Strict: " + strict);
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class Fly extends MiniPlugin implements Detector
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void updateFlyhack(PlayerMoveEvent event)
|
||||
{
|
||||
if (!Host.IsEnabled())
|
||||
if (!Host.isEnabled())
|
||||
return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
@ -32,7 +32,7 @@ public class Idle extends MiniPlugin implements Detector
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void updateFlyhack(PlayerMoveEvent event)
|
||||
{
|
||||
if (!Host.IsEnabled())
|
||||
if (!Host.isEnabled())
|
||||
return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
@ -43,7 +43,7 @@ public class Idle extends MiniPlugin implements Detector
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void updateFreeCam(UpdateEvent event)
|
||||
{
|
||||
if (!Host.IsEnabled())
|
||||
if (!Host.isEnabled())
|
||||
return;
|
||||
|
||||
if (event.getType() != UpdateType.FAST)
|
||||
|
@ -38,7 +38,7 @@ public class Reach extends MiniPlugin implements Detector
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void recordMove(UpdateEvent event)
|
||||
{
|
||||
if (!Host.IsEnabled())
|
||||
if (!Host.isEnabled())
|
||||
return;
|
||||
|
||||
if (event.getType() != UpdateType.TICK)
|
||||
|
@ -33,7 +33,7 @@ public class Speed extends MiniPlugin implements Detector
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void updateSpeedhack(PlayerMoveEvent event)
|
||||
{
|
||||
if (!Host.IsEnabled())
|
||||
if (!Host.isEnabled())
|
||||
return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
Loading…
Reference in New Issue
Block a user