Need to improve rate limit logic
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -18,10 +18,10 @@ public class NBTConfig implements JsonSerializable<NBTConfig> {
|
|||||||
|
|
||||||
public class RateLimit {
|
public class RateLimit {
|
||||||
public int rateLimitBytes = 16348;
|
public int rateLimitBytes = 16348;
|
||||||
public int byteDecay = 1024;
|
public int byteDecay = 1024; // Every Minute
|
||||||
public int rateLimitItems = 10;
|
public int rateLimitItems = 10;
|
||||||
public int itemDecay = 2;
|
public int itemDecay = 5; // Every 10 seconds
|
||||||
public List<String> punishmentCommands = List.of("kick %player% Internal Exception: io.netty.handler.codec.DecoderException: java.lang.RuntimeException: Tried to read NBT tag that was too big; tried to allocate 28391038bytes where max allowed: 16348");
|
public List<String> punishmentCommands = List.of("kick %player% Internal Exception: io.netty.handler.codec.DecoderException: java.lang.RuntimeException: Tried to read NBT tag that was too big; tried to allocate %s bytes where max allowed: %s");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean allowName = true;
|
public boolean allowName = true;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import org.bukkit.event.inventory.InventoryCreativeEvent;
|
|||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CreativeHotbar extends AbstractViolation {
|
public class CreativeHotbar extends AbstractViolation {
|
||||||
@@ -42,6 +43,11 @@ public class CreativeHotbar extends AbstractViolation {
|
|||||||
//ServerUtils.verbose("NBT: Cursor has meta");
|
//ServerUtils.verbose("NBT: Cursor has meta");
|
||||||
if (!(i.hasItemMeta() && i.getItemMeta() != null)) return;
|
if (!(i.hasItemMeta() && i.getItemMeta() != null)) return;
|
||||||
if (!new RateLimitCheck().passes(new Pair<>(p,i))) {
|
if (!new RateLimitCheck().passes(new Pair<>(p,i))) {
|
||||||
|
List<String> punishmentCommands = new ArrayList<>();
|
||||||
|
for (String punishmentCommand : Sentinel.getInstance().getDirector().io.nbtConfig.rateLimit.punishmentCommands) {
|
||||||
|
punishmentCommands.add(punishmentCommand.formatted());
|
||||||
|
}
|
||||||
|
|
||||||
ServerUtils.verbose("Player flags rate limit, performing action");
|
ServerUtils.verbose("Player flags rate limit, performing action");
|
||||||
ActionConfiguration.Builder config = new ActionConfiguration.Builder()
|
ActionConfiguration.Builder config = new ActionConfiguration.Builder()
|
||||||
.setEvent(e)
|
.setEvent(e)
|
||||||
@@ -49,7 +55,7 @@ public class CreativeHotbar extends AbstractViolation {
|
|||||||
.cancel(true)
|
.cancel(true)
|
||||||
.punish(true)
|
.punish(true)
|
||||||
.deop(Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.deop)
|
.deop(Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.deop)
|
||||||
.setPunishmentCommands(Sentinel.getInstance().getDirector().io.nbtConfig.rateLimit.punishmentCommands);
|
.setPunishmentCommands();
|
||||||
|
|
||||||
runActions(
|
runActions(
|
||||||
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.grab, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.nbtItem),
|
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.grab, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.nbtItem),
|
||||||
|
|||||||
@@ -14,9 +14,32 @@ import org.bukkit.inventory.meta.BlockStateMeta;
|
|||||||
import org.bukkit.inventory.meta.BundleMeta;
|
import org.bukkit.inventory.meta.BundleMeta;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ItemCheck extends AbstractCheck<ItemStack> {
|
public class ItemCheck extends AbstractCheck<ItemStack> {
|
||||||
|
|
||||||
|
public List<AbstractCheck<ItemStack>> checks;
|
||||||
|
|
||||||
|
public ItemCheck() {
|
||||||
|
enchantmentCheck = new EnchantmentCheck();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean passes(ItemStack item) {
|
public boolean passes(ItemStack item) {
|
||||||
|
try {
|
||||||
|
return scan(item);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Sentinel.getInstance().getLogger().warning("Caught an exception while handling an item check: " + Arrays.toString(ex.getStackTrace()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checksPass(ItemStack item) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean scan(ItemStack item) {
|
||||||
ServerUtils.verbose("Checking item: " + item.getType().name());
|
ServerUtils.verbose("Checking item: " + item.getType().name());
|
||||||
NBTConfig config = Sentinel.getInstance().getDirector().io.nbtConfig;
|
NBTConfig config = Sentinel.getInstance().getDirector().io.nbtConfig;
|
||||||
|
|
||||||
@@ -189,7 +212,7 @@ public class ItemCheck extends AbstractCheck<ItemStack> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSpawnEgg(ItemStack item) {
|
private boolean isSpawnEgg(ItemStack item) {
|
||||||
return item.getType().name().toLowerCase().contains("spawn_egg");
|
return item.getType().name().toLowerCase().contains("spawn_egg");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ public final class Loader {
|
|||||||
Bukkit.getScheduler().runTaskTimer(Sentinel.getInstance(), SpamFilter::decayHeat,0, 20);
|
Bukkit.getScheduler().runTaskTimer(Sentinel.getInstance(), SpamFilter::decayHeat,0, 20);
|
||||||
Bukkit.getScheduler().runTaskTimer(Sentinel.getInstance(), ProfanityFilter::decayScore,0,1200);
|
Bukkit.getScheduler().runTaskTimer(Sentinel.getInstance(), ProfanityFilter::decayScore,0,1200);
|
||||||
Bukkit.getScheduler().runTaskTimer(Sentinel.getInstance(), WandEvents::handleDisplay,0,1);
|
Bukkit.getScheduler().runTaskTimer(Sentinel.getInstance(), WandEvents::handleDisplay,0,1);
|
||||||
Bukkit.getScheduler().runTaskTimer(Sentinel.getInstance(), RateLimitCheck::decayData,0,20*60);
|
Bukkit.getScheduler().runTaskTimer(Sentinel.getInstance(), RateLimitCheck::decayData,0,1200);
|
||||||
Bukkit.getScheduler().runTaskTimer(Sentinel.getInstance(), RateLimitCheck::decayItems,0,200);
|
Bukkit.getScheduler().runTaskTimer(Sentinel.getInstance(), RateLimitCheck::decayItems,0,200);
|
||||||
|
|
||||||
if (Sentinel.getInstance().getDirector().io.mainConfig.backdoorDetection.enabled) Sentinel.getInstance().getDirector().backdoorDetection.init();
|
if (Sentinel.getInstance().getDirector().io.mainConfig.backdoorDetection.enabled) Sentinel.getInstance().getDirector().backdoorDetection.init();
|
||||||
|
|||||||
Reference in New Issue
Block a user