Dieser Commit ist enthalten in:
Ursprung
ae638bb2bf
Commit
f74253f4cb
@ -27,12 +27,20 @@ import de.steamwar.techhider.ProtocolUtils;
|
|||||||
import de.steamwar.techhider.TechHider;
|
import de.steamwar.techhider.TechHider;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class AntiNocom {
|
public class AntiNocom implements Listener {
|
||||||
|
|
||||||
|
private final Map<Player, Integer> flags = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public AntiNocom() {
|
public AntiNocom() {
|
||||||
|
Bukkit.getServer().getPluginManager().registerEvents(this, Core.getInstance());
|
||||||
TinyProtocol.instance.addFilter(blockDig, this::onDig);
|
TinyProtocol.instance.addFilter(blockDig, this::onDig);
|
||||||
|
|
||||||
if(Core.getVersion() > 8) {
|
if(Core.getVersion() > 8) {
|
||||||
@ -40,6 +48,11 @@ public class AntiNocom {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onQuit(PlayerQuitEvent e) {
|
||||||
|
flags.remove(e.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
private void registerUseItem() {
|
private void registerUseItem() {
|
||||||
Class<?> useItem = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem");
|
Class<?> useItem = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem");
|
||||||
|
|
||||||
@ -56,16 +69,7 @@ public class AntiNocom {
|
|||||||
|
|
||||||
TinyProtocol.instance.addFilter(useItem, (player, packet) -> {
|
TinyProtocol.instance.addFilter(useItem, (player, packet) -> {
|
||||||
Object pos = getPosition.apply(packet);
|
Object pos = getPosition.apply(packet);
|
||||||
int x = TechHider.blockPositionX.get(pos);
|
return isValid(player, "UseItem", TechHider.blockPositionX.get(pos), TechHider.blockPositionZ.get(pos)) ? packet : null;
|
||||||
int z = TechHider.blockPositionZ.get(pos);
|
|
||||||
|
|
||||||
if(!player.getWorld().isChunkLoaded(ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(z))) {
|
|
||||||
Bukkit.getScheduler().runTask(Core.getInstance(), () -> player.kickPlayer(null));
|
|
||||||
SWException.log(player.getName() + " kicked for using item on unloaded block (potential NoCom-DOS attack)", x + " " + z);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return packet;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,13 +77,20 @@ public class AntiNocom {
|
|||||||
private static final Reflection.FieldAccessor<?> digPosition = Reflection.getField(blockDig, TechHider.blockPosition, 0);
|
private static final Reflection.FieldAccessor<?> digPosition = Reflection.getField(blockDig, TechHider.blockPosition, 0);
|
||||||
private Object onDig(Player player, Object packet) {
|
private Object onDig(Player player, Object packet) {
|
||||||
Object pos = digPosition.get(packet);
|
Object pos = digPosition.get(packet);
|
||||||
int x = TechHider.blockPositionX.get(pos);
|
return isValid(player, "Dig", TechHider.blockPositionX.get(pos), TechHider.blockPositionZ.get(pos)) ? packet : null;
|
||||||
int z = TechHider.blockPositionZ.get(pos);
|
}
|
||||||
if((x != 0 || z != 0) && !player.getWorld().isChunkLoaded(ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(z))) {
|
|
||||||
|
private boolean isValid(Player player, String type, int x, int z) {
|
||||||
|
if((x == 0 && z == 0) || player.getWorld().isChunkLoaded(ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(z)))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
int amount = flags.compute(player, (p, a) -> a == null ? 1 : a+1);
|
||||||
|
if(amount % 8 == 0) { // Only after 8 and every 8 to reduce false flags and spam
|
||||||
|
if(amount == 8) // Schedule player kick only once
|
||||||
Bukkit.getScheduler().runTask(Core.getInstance(), () -> player.kickPlayer(null));
|
Bukkit.getScheduler().runTask(Core.getInstance(), () -> player.kickPlayer(null));
|
||||||
SWException.log(player.getName() + " kicked for digging an unloaded block (potential NoCom-DOS attack)", x + " " + z);
|
|
||||||
return null;
|
SWException.log(player.getName() + " kicked for potential NoCom-DOS attack", x + " " + z + " " + type + " " + amount);
|
||||||
}
|
}
|
||||||
return packet;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren