Skip to content

Commit

Permalink
Prevent firework abuse
Browse files Browse the repository at this point in the history
  • Loading branch information
SamB440 committed Jun 15, 2024
1 parent 7d2cd5a commit 0318693
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ac.grim.grimac.events.packets;

import ac.grim.grimac.GrimAPI;
import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.type.PacketCheck;
import ac.grim.grimac.player.GrimPlayer;
Expand Down Expand Up @@ -47,6 +48,9 @@ public class PacketEntityReplication extends Check implements PacketCheck {
// Another valid solution is to simply spam more transactions, but let's not waste bandwidth.
private final List<Integer> despawnedEntitiesThisTransaction = new ArrayList<>();

// Maximum ping when a firework boost is removed from the player.
private final int maxFireworkBoostPing = GrimAPI.INSTANCE.getConfigManager().getConfig().getIntElse("max-ping-firework-boost", 1000);

public PacketEntityReplication(GrimPlayer player) {
super(player);
}
Expand Down Expand Up @@ -300,12 +304,26 @@ public void onPacketSend(PacketSendEvent event) {
}
}

player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get() + 1, () -> {
final int destroyTransaction = player.lastTransactionSent.get() + 1;
player.latencyUtils.addRealTimeTask(destroyTransaction, () -> {
for (int integer : destroyEntityIds) {
player.compensatedEntities.removeEntity(integer);
player.compensatedFireworks.removeFirework(integer);
}
});

// Don't let the player freeze transactions to keep the firework boost velocity + uncertainty
// Also generally prevents people with high ping gaining too high an advantage in firework use
player.runNettyTaskInMs(() -> {
if (player.lastTransactionReceived.get() >= destroyTransaction) return;
for (int entityID : destroyEntityIds) {
// If the player has a firework boosting them, setback
if (player.compensatedFireworks.hasFirework(entityID)) {
player.getSetbackTeleportUtil().executeViolationSetback();
break;
}
}
}, maxFireworkBoostPing);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import ac.grim.grimac.checks.type.PostPredictionCheck;
import ac.grim.grimac.player.GrimPlayer;
import ac.grim.grimac.utils.anticheat.update.PredictionComplete;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;

import java.util.HashSet;
import java.util.Set;

public class CompensatedFireworks extends Check implements PostPredictionCheck {

// As this is sync to one player, this does not have to be concurrent
IntList activeFireworks = new IntArrayList();
IntList fireworksToRemoveNextTick = new IntArrayList();
private final Set<Integer> activeFireworks = new HashSet<>();
private final Set<Integer> fireworksToRemoveNextTick = new HashSet<>();

public CompensatedFireworks(GrimPlayer player) {
super(player);
Expand All @@ -24,6 +26,10 @@ public void onPredictionComplete(final PredictionComplete predictionComplete) {
fireworksToRemoveNextTick.clear();
}

public boolean hasFirework(int entityId) {
return activeFireworks.contains(entityId);
}

public void addNewFirework(int entityID) {
activeFireworks.add(entityID);
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/config/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,8 @@ packet-spam-threshold: 100
# Dies liegt daran, dass Grim derzeit fliegende Spieler nicht überprüft.
max-ping-out-of-flying: 1000

# Maximum ping when a firework boost is removed from the player.
# This prevents high latency players from being able to use 1 firework boost with an elytra forever.
max-ping-firework-boost: 1000

config-version: 9
4 changes: 4 additions & 0 deletions src/main/resources/config/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,8 @@ packet-spam-threshold: 100
# This is due to Grim not currently checking flying players
max-ping-out-of-flying: 1000

# Maximum ping when a firework boost is removed from the player.
# This prevents high latency players from being able to use 1 firework boost with an elytra forever.
max-ping-firework-boost: 1000

config-version: 9
4 changes: 4 additions & 0 deletions src/main/resources/config/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,8 @@ packet-spam-threshold: 100
# Esto se debe a que Grim actualmente no revisa a los jugadores que están volando.
max-ping-out-of-flying: 1000

# Maximum ping when a firework boost is removed from the player.
# This prevents high latency players from being able to use 1 firework boost with an elytra forever.
max-ping-firework-boost: 1000

config-version: 9
4 changes: 4 additions & 0 deletions src/main/resources/config/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,8 @@ packet-spam-threshold: 100
# Cela est dû au fait que Grim ne vérifie pas actuellement les joueurs en vol.
max-ping-out-of-flying: 1000

# Maximum ping when a firework boost is removed from the player.
# This prevents high latency players from being able to use 1 firework boost with an elytra forever.
max-ping-firework-boost: 1000

config-version: 9
13 changes: 11 additions & 2 deletions src/main/resources/config/it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,22 @@ exploit:
# Distanza per controllare i ghost blocks
distance-to-check-if-ghostblocks: 2

# Enable logging plugins who have injected into netty on join to debug compatibility issues
debug-pipeline-on-join: false

# Enables experimental checks
experimental-checks: false

# Grim sometimes cancels illegal packets such as with timer, after X packets in a second cancelled, when should
# we simply kick the player? This is required as some packet limiters don't count packets cancelled by grim.
packet-spam-threshold: 100

max-ping-out-of-flying: 1000
# Grim is able to enforce that a player set out of flying state cannot have more than X milliseconds of ping
# This is due to Grim not currently checking flying players
max-ping-out-of-flying: 1000
max-ping-out-of-flying: 1000

# Maximum ping when a firework boost is removed from the player.
# This prevents high latency players from being able to use 1 firework boost with an elytra forever.
max-ping-firework-boost: 1000

config-version: 9
4 changes: 4 additions & 0 deletions src/main/resources/config/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,8 @@ packet-spam-threshold: 100
# Dit komt doordat Grim momenteel vliegende spelers niet controleert
max-ping-out-of-flying: 1000

# Maximum ping when a firework boost is removed from the player.
# This prevents high latency players from being able to use 1 firework boost with an elytra forever.
max-ping-firework-boost: 1000

config-version: 9
4 changes: 4 additions & 0 deletions src/main/resources/config/pt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,8 @@ packet-spam-threshold: 100
# Isso ocorre porque o Grim atualmente não verifica os jogadores que estão voando.
max-ping-out-of-flying: 1000

# Maximum ping when a firework boost is removed from the player.
# This prevents high latency players from being able to use 1 firework boost with an elytra forever.
max-ping-firework-boost: 1000

config-version: 9
4 changes: 4 additions & 0 deletions src/main/resources/config/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,8 @@ packet-spam-threshold: 100
# Это связано с тем, что Грим в настоящее время не проверяет летающих игроков.
max-ping-out-of-flying: 1000

# Maximum ping when a firework boost is removed from the player.
# This prevents high latency players from being able to use 1 firework boost with an elytra forever.
max-ping-firework-boost: 1000

config-version: 9
4 changes: 4 additions & 0 deletions src/main/resources/config/zh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,8 @@ packet-spam-threshold: 100
# Grim 能够强制执行一个规则:被设置为非飞行状态的玩家的 ping 值不能超过 X 毫秒。这是因为 Grim 目前不检查处于飞行状态的玩家。
max-ping-out-of-flying: 1000

# Maximum ping when a firework boost is removed from the player.
# This prevents high latency players from being able to use 1 firework boost with an elytra forever.
max-ping-firework-boost: 1000

config-version: 9

0 comments on commit 0318693

Please sign in to comment.