Skip to content

Commit

Permalink
Fix, Add many, working on something, new TimerCheck
Browse files Browse the repository at this point in the history
Timer(B) is really flawless....
Timer(A) will removed soon
  • Loading branch information
mgmgprndev committed Sep 18, 2024
1 parent 7f869f4 commit 27d396e
Show file tree
Hide file tree
Showing 17 changed files with 186 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.mogukun</groupId>
<artifactId>Sentry</artifactId>
<version>0.2.4</version>
<version>0.2.5</version>
<packaging>jar</packaging>

<name>Sentry</name>
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/mogukun/sentry/Sentry.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.mogukun.sentry;

import com.mogukun.sentry.check.CheckManager;
import com.mogukun.sentry.check.Plan;
import com.mogukun.sentry.listeners.MessageListener;
import com.mogukun.sentry.managers.PlayerDataManager;
import com.mogukun.sentry.commands.SentryCommand;
import com.mogukun.sentry.gui.GUIManager;
Expand Down Expand Up @@ -29,6 +31,7 @@ public final class Sentry extends JavaPlugin {
public HashMap<UUID,Integer> alertStatus = new HashMap<>();

public Configuration config;
public Plan plan = Plan.Free;
public GUIManager guiManager;
public ConfigurationUtil configurationUtil;

Expand All @@ -38,7 +41,6 @@ public void onEnable() {
long startLoading = System.currentTimeMillis();

System.out.println("[Sentry] Loading Sentry AntiCheat");

this.instance = this;
saveDefaultConfig();
config = getConfig();
Expand All @@ -52,6 +54,7 @@ public void onEnable() {
getCommand("sentry").setExecutor( new SentryCommand() );
Sentry.instance.checkManager.checkMap.clear();
Sentry.instance.checkManager.vl.clear();
Bukkit.getMessenger().registerIncomingPluginChannel(this,"mc|brand", new MessageListener());

System.out.println("[Sentry] Loaded Sentry AntiCheat in " + ( System.currentTimeMillis() - startLoading ) + "ms.");
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/mogukun/sentry/check/CheckInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
String description();
Category category();
boolean experimental() default false;
Plan plan() default Plan.Free;

}
3 changes: 2 additions & 1 deletion src/main/java/com/mogukun/sentry/check/CheckManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.mogukun.sentry.check.checks.combats.aura.AuraB;
import com.mogukun.sentry.check.checks.combats.aura.AuraC;
import com.mogukun.sentry.check.checks.combats.autoclicker.AutoClickerA;
import com.mogukun.sentry.check.checks.combats.autoclicker.AutoClickerB;
import com.mogukun.sentry.check.checks.combats.blockhit.BlockHitA;
import com.mogukun.sentry.check.checks.combats.reach.ReachA;
import com.mogukun.sentry.check.checks.movements.fly.*;
Expand All @@ -23,6 +22,7 @@
import com.mogukun.sentry.check.checks.players.noslow.NoSlowSword;
import com.mogukun.sentry.check.checks.players.pingspoof.PingSpoofA;
import com.mogukun.sentry.check.checks.players.timer.TimerA;
import com.mogukun.sentry.check.checks.players.timer.TimerB;
import com.mogukun.sentry.models.MovementData;
import com.mogukun.sentry.models.ViolationData;
import com.mogukun.sentry.utils.PlayerDataUtil;
Expand Down Expand Up @@ -78,6 +78,7 @@ public CheckManager(){
checks.add( new GroundSpoofC() );

checks.add( new TimerA() );
checks.add( new TimerB() );

checks.add( new BadPacketA() );
checks.add( new BadPacketB() );
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/mogukun/sentry/check/Plan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.mogukun.sentry.check;

public enum Plan {
Free,
Dev
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mogukun.sentry.check.Category;
import com.mogukun.sentry.check.Check;
import com.mogukun.sentry.check.CheckInfo;
import com.mogukun.sentry.models.Counter;
import net.minecraft.server.v1_8_R3.Packet;
import net.minecraft.server.v1_8_R3.PacketPlayInArmAnimation;
import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity;
Expand All @@ -15,23 +16,24 @@
)
public class AuraC extends Check {

long lastArm = 0;
Counter armCounter = new Counter();
Counter attackCounter = new Counter();

@Override
public void handle(Packet packet) {
long now = System.currentTimeMillis();
if ( packet instanceof PacketPlayInArmAnimation) {
lastArm = now;
if ( getPlayerData().isDigging ) return;
armCounter.count();
}
if ( packet instanceof PacketPlayInUseEntity ) {

if ( ((PacketPlayInUseEntity) packet).a() != PacketPlayInUseEntity.EnumEntityUseAction.ATTACK ) return;

long diff = now - lastArm;
attackCounter.count();

if ( diff > 10 ) {
flag("diff=" + diff);
}
int difference = attackCounter.count() - armCounter.getCount();

//debug("difference=" + difference);

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public void handle(MovementData data)
data.sinceStandingOnBoatTick <= 10 ||
data.sinceWebTick <= 10 ||
data.sinceWaterTick <= 10 ||
data.sinceClimbTick <= 10 ) return;
data.sinceClimbTick <= 10 ||
data.sinceSlimeTick <= 20) return;
if ( data.serverAirTick < 1 ) {
buffer = 0;
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ public void handle(MovementData data)
buffer = 0;
return;
}
if ( data.sinceVehicleTick <= 10 || data.sinceStandingOnBoatTick <= 10 || data.sinceWebTick <= 10 || data.sinceWaterTick <= 10 || data.sinceClimbTick <= 10 ) return;
if ( data.sinceVehicleTick <= 10 ||
data.sinceStandingOnBoatTick <= 10 ||
data.sinceWebTick <= 10 ||
data.sinceWaterTick <= 10 ||
data.sinceClimbTick <= 10 ||
data.sinceSlimeTick <= 20) return;
if ( data.sinceVelocityTaken < 5 ) return;

// Credit: CheatGuard @DerRedstoner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
category = Category.MOVEMENT
)
public class FlyC extends Check {

Counter counter = new Counter();

@Override
Expand All @@ -25,7 +24,8 @@ public void handle(MovementData data)
return;
}

if ( data.sinceVehicleTick <= 10 || data.sinceStandingOnBoatTick <= 10 || data.sinceWebTick <= 10 || data.sinceWaterTick <= 10 || data.sinceClimbTick <= 10 ) return;
if ( data.sinceVehicleTick <= 10 || data.sinceStandingOnBoatTick <= 10
|| data.sinceWebTick <= 10 || data.sinceWaterTick <= 10 || data.sinceClimbTick <= 10 || data.sinceSlimeTick <= 10) return;

if ( data.currentY < data.lastY && data.currentDeltaY <= data.lastDeltaY ) {
if ( counter.count() > config.getDoubleOrDefault("flag_buffer", 5) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void handle(MovementData data)
} else bufferCounter.count(-150);

double bufferCount = bufferCounter.getCount();
if ( bufferCount > 0 ) {
if ( bufferCount > config.getDoubleOrDefault("flag_buffer", 500) ) {
flag("buffer1=" + bufferCount + " buffer2=" + totalBuffer + " sampleSize=" + samples.size() );
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.mogukun.sentry.check.checks.players.timer;
import com.mogukun.sentry.check.*;
import com.mogukun.sentry.models.*;
import com.mogukun.sentry.models.Counter;
import net.minecraft.server.v1_8_R3.*;
import org.bukkit.event.Event;
import org.bukkit.event.player.PlayerJoinEvent;
import java.util.*;

@CheckInfo(
name = "Timer (B)",
path = "player.timer.b",
description = "Designed for Stable Timer Check",
category = Category.PLAYER
)
public class TimerB extends Check {

long lastPacket = 0;
long startIgnore = 0;
double lastPercentage = 0;

BetterCounter deltaCounter = new BetterCounter(1000 * 60);
Counter buffer = new Counter();

@Override
public void handle(Packet packet) {
if ( packet instanceof PacketPlayInFlying )
{
long now = System.nanoTime();

if ( lastPacket == 0 ||
getPlayerData().teleportTick <= 5 ||
getPlayerData().respawnTick <= 5 ||
System.currentTimeMillis() - startIgnore < 10000 ) {

lastPacket = now;
return;
}
deltaCounter.count( now - lastPacket );

if ( deltaCounter.size() > 60 ) {
long avg = averageWithoutOutliers(deltaCounter.getLongList());

// somehow this is weird. this return 50% if player is 50% faster.
double percentage = ((double)avg / 50000000) * 100;
percentage -= 100; // so get difference.
percentage = 100 - percentage;

if( percentage > 105 || percentage < 95 ) {
int bufferCount = buffer.count();
if ( bufferCount > 10 ) {
flag("percentage=" + percentage + " buffer=" + bufferCount + " size=" + deltaCounter.size() );
deltaCounter.clear();
}
}

lastPercentage = percentage;
}


lastPacket = now;
}
}

@Override
public void event(Event event) {
if ( event instanceof PlayerJoinEvent) {
startIgnore = System.currentTimeMillis();
}
}


public long averageWithoutOutliers(ArrayList<Long> list) {
Collections.sort(list);
int size = list.size();
long q1 = list.get(size / 4);
long q3 = list.get(3 * size / 4);
double iqr = q3 - q1;
double lowerBound = q1 - 1.5 * iqr;
double upperBound = q3 + 1.5 * iqr;
ArrayList<Long> filteredList = new ArrayList<>();
for (long num : list) {
if (num >= lowerBound && num <= upperBound) {
filteredList.add(num);
}
}
if (filteredList.isEmpty()) {
return 50;
}

long sum = 0;
for (long num : filteredList) {
sum += num;
}

return sum / filteredList.size();
}

}
5 changes: 3 additions & 2 deletions src/main/java/com/mogukun/sentry/gui/guis/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ public Inventory createGUI(Player player) {

inv.setItem(13, createStack(Material.PAPER, "&6Sentry Information", new ListUtil().
add("&1").
add("&6Type &f" + Sentry.instance.plan).
add("&6Version &f" + Sentry.instance.getDescription().getVersion()).
add("&6Author &f" + (authors.size() > 1 ? String.join(", ", authors) : authors.get(0)) ).
add("&6Description").
add("&f" + Sentry.instance.getDescription().getDescription() ).
add("&6Version &f" + Sentry.instance.getDescription().getVersion())
add("&f" + Sentry.instance.getDescription().getDescription() )
.getList()));


Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/mogukun/sentry/listeners/MessageListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mogukun.sentry.listeners;

import com.mogukun.sentry.Sentry;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;

import java.io.UnsupportedEncodingException;

public class MessageListener implements PluginMessageListener {
@Override
public void onPluginMessageReceived(String s, Player player, byte[] bytes) {
String brand = "Unknown";
try {
brand = new String(bytes, "UTF-8").substring(1);
} catch (UnsupportedEncodingException ignore) {}
Sentry.instance.dataManager.getPlayerData(player).clientBrand = brand;
System.out.println(brand);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public void onJoin(PlayerJoinEvent event) {
new PacketHandler(event.getPlayer()))
);



call(event.getPlayer(), event);
}

Expand Down
29 changes: 26 additions & 3 deletions src/main/java/com/mogukun/sentry/models/BetterCounter.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
package com.mogukun.sentry.models;

import java.util.ArrayList;
import java.util.concurrent.ConcurrentLinkedDeque;

public class BetterCounter {

ConcurrentLinkedDeque<DoubleLong> counts = new ConcurrentLinkedDeque<>();

long interval = 1000000000;

public BetterCounter() {}

public BetterCounter(long interval) {
this.interval = interval * 1000000;
}

public double count(double d) {
long now = System.currentTimeMillis();
long now = System.nanoTime();
counts.add( new DoubleLong(d,now) );
return getCount(now);
}

public double getCount() {
return getCount(System.currentTimeMillis());
return getCount(System.nanoTime());
}

private double getCount(long now) {
counts.removeIf(k -> now - k.b > 1000);
counts.removeIf(k -> now - k.b >= interval);
double t = 0;
for ( DoubleLong l : counts ) t += l.a;
return t;
Expand All @@ -29,4 +36,20 @@ public void clear() {
counts.clear();
}

public int size() {
return counts.size();
}

public ArrayList<Double> getDoubleList() {
ArrayList<Double> temp = new ArrayList<>();
for ( DoubleLong l : counts ) temp.add(l.a);
return temp;
}

public ArrayList<Long> getLongList() {
ArrayList<Long> temp = new ArrayList<>();
for ( DoubleLong l : counts ) temp.add((long)l.a);
return temp;
}

}
1 change: 1 addition & 0 deletions src/main/java/com/mogukun/sentry/models/PlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class PlayerData {
public PlayerData() {}

public MovementData data = null;
public String clientBrand = "";
public boolean isDigging = false;
public long lastPlace = 0;
public boolean runningTransactionPingCheck = false;
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
license: "FREE"
# will auto generated AFTER LOAD THE PLUGIN!
checks:

0 comments on commit 27d396e

Please sign in to comment.