BeansAC
一款面向 Minecraft 的服务端反作弊模组。放入服务器,通过 TOML 配置文件进行设置,即可良好运行。
设计理念
大多数反作弊在模组服上失效,是因为它们硬编码了原版游戏的假设。BeansAC 采取了不同的方法:
- 注册表扫描:在启动时扫描所有 Forge 注册表,识别模组添加的方块、物品、附魔和效果。动态调整检测阈值,而非维护兼容性列表。
- 物理模拟:运行基于每个玩家的移动模拟,考虑活跃的效果、附魔和环境条件。标记偏离预期行为的情况,而不是使用平均硬编码的速度上限。(这部分花了我好几个小时才完成。)
- 基于事务的延迟处理:在连接层追踪每个玩家的往返时间 (RTT)。利用此数据调整距离、速度和时间检查,防止对高延迟玩家产生误判。
- 服务器卡顿韧性:当服务器刻时间超过 100ms 或单个玩家延迟激增时,所有检查都会跳过。
27 项活跃检查
| 包 |
检查项 |
| Movement(移动) |
Speed(速度)、Flight(飞行)、Phase(相位/穿墙,200 刻宽限期)、NoFall(无掉落伤害)、Timer(计时器,1.5s 窗口,2.5x 比率)、Velocity(速度推击)、Jesus(水上行走)、Elytra(鞘翅)、Vehicle(载具) |
| Combat(战斗) |
Reach(攻击距离)、AutoClicker(自动点击)、AttackCooldown(攻击冷却)、AutoBlock(自动格挡,使用物品→攻击在 50ms 内)、HitBox(命中框,实体包围盒 ≥4.5) |
| Inventory(物品栏) |
Dupe(复制)、Container(容器,槽位边界 + DataValidator NBT 验证)、CreativeMatch(创造模式匹配,创造模式生成物品的验证) |
| Protocol(协议) |
BadPackets(坏数据包,NaN/无限值/俯仰角边界)、PingSpoof(延迟欺骗,200 刻宽限期,适应卡顿)、PacketOrder(数据包顺序,攻击/挥舞顺序 + 挖掘状态机)、PayloadRate(载荷速率,每秒 10 个自定义载荷) |
| World(世界) |
Scaffold(搭路)、FastBreak(快速破坏,基于每个方块的追踪,ABORT/START 序列)、FastPlace(快速放置,30ms 间隔)、Nuker(炸矿,射线追踪视线遮挡 + 模式检测) |
每项检查均可单独配置:enabled(启用)、maxVl(最大违规等级)和 punishment(惩罚方式:踢出/封禁/警报)。
模组感知架构
BeansAC 不进行硬编码兼容。在启动时:
- RegistryScanner(注册表扫描器):遍历所有 Forge 注册表(物品、方块、附魔、生物效果、实体)。缓存哈希值以供后续启动使用。
- MovementSimulation(移动模拟):在运行时通过扫描玩家当前的活跃效果和穿戴的附魔来计算每个玩家的最大速度,使模组效果自动扩展允许范围。
- PossibilityMap(可能性映射):标记未知的附魔/效果并应用宽松的多重乘数,而不是直接判定为违规。
- SandboxManager(沙箱管理器)(可选):当检测到不确定行为时,启动无头 Forge JVM,将数据包针对实际模组代码进行测试。
数据验证
DataValidator(数据验证器) 单例验证所有通过任何途径进入服务器的物品 NBT 数据:
- 容器点击 (
ServerboundContainerClickPacket)
- 创造模式物品栏 (
ServerboundSetCreativeModeSlotPacket)
- 书本编辑 (
ServerboundEditBookPacket — 页数、页面长度、控制字符)
- 铁砧重命名 (
ServerboundRenameItemPacket — 名称长度)
- 附魔注册与等级合理性
- NBT 深度限制(防止递归标签炸弹)
- 烟花效果数量、头颅纹理大小
抗误判能力
BeansAC 优先考虑降低假阴性(漏报)而非假阳性(误报)。关键缓解措施包括:
- 线程安全 —
PacketInterceptor.onInboundPacket() 和 onOutboundPacket() 使用 server.isSameThread() 进行保护。防止 Netty IO 线程导致的状态损坏。
- 服务器卡顿跳过 — 当
server.getAverageTickTime() > 100ms 或单个玩家延迟激增时,CheckManager.runAll() 会提前返回。
- 宽限期 — PhaseCheck 在生成/传送后等待 200 刻。PingSpoofCheck 等待 200 刻。AutoClickerCheck 需要 12+ 个样本。
- RTT 补偿 — Reach、AttackCooldown 和 Velocity 检查会考虑每个玩家的平滑 RTT。
- 违规等级衰减 — 违规等级每服务器刻减少 1,防止累积的误判惩罚。
- 模组物品宽容度 — ElytraCheck 接受胸甲槽中任何非原版的物品作为潜在的鞘翅,而不仅仅是
minecraft:elytra。
- 基于碰撞的方块检测 — PhaseCheck 使用
getCollisionShape().isEmpty() 而不是硬编码白名单,从而适配来自任何模组的任何非固体方块。
性能
- 通过循环缓冲区实现 O(1) 状态历史记录(无需数组拷贝)
- 基于
AtomicReferenceArray 后端的每玩家补偿世界
- CheckManager 使用高效的基于类的分发机制
- 轻量级的每刻状态同步
配置
基于 TOML (config/beansac.toml)。分三个阶段加载:通过 ForgeConfigSpec.Builder 定义所有值,通过 CommentedFileConfig 加载文件,然后构建不可变配置对象。提供 Anti-Xray(反透视)、沙箱、延迟和 webhook 相关部分。
取消逻辑接线
所有调用 requestCancel() 的检查都已连接到 mixin 层并真正取消数据包:
- ReachCheck 通过
ReachCheck.validate() 的返回值取消 handleInteract、handleUseItemOn、handlePlayerAction
- NukerCheck 通过
consumeCancel() 取消 handlePlayerAction
- FastBreakCheck 通过
consumeCancel() 取消 handlePlayerAction
- ScaffoldCheck 通过
consumeCancel() 取消 handleUseItemOn
- FastPlaceCheck 通过
consumeCancel() 取消 handleUseItemOn
- AutoBlockCheck 通过
consumeCancel() 取消 handleInteract
- HitBoxCheck 通过
consumeCancel() 取消 handleInteract
- ContainerCheck 通过
consumeCancel() 取消 handleContainerClick
- CreativeMatchCheck 通过
consumeCancel() 取消 handleSetCreativeModeSlot
- PacketOrderCheck 通过
consumeCancel() 取消 handlePlayerAction
- PayloadRateCheck 通过
consumeCancel() 取消 handleCustomPayload
所有取消路径都会触发 resyncBlock() 以防止方块不同步(幽灵方块)。
客户端品牌检测
解析 minecraft:brand 载荷字符串,并检测已知客户端(forge, fabric, lunar, badlion, wurst, FastMath, 作弊关键词等)。可通过 /beansac debug 命令按玩家显示。
依赖项:
- Minecraft Forge, Java 17
Top4eat21's topeatLib
命令
| 命令 |
描述 |
/beansac alerts |
切换实时警报 |
/beansac vl <player> |
显示违规等级 |
/beansac checks |
列出所有检查项及其状态 |
/beansac debug <player> |
显示客户端品牌 + 已检测到的特征 |
许可证
12Tae12 Protective License,详见 此处。
BeansAC
A server-side anticheat for Minecraft. Drop in, configure via TOML, and it works pretty good.
Philosophy
Most anticheats fail on modded servers because they hardcode Vanilla assumptions. BeansAC takes a different approach:
- Registry-scanning at startup, scans all Forge registries for modded blocks, items, enchants, and effects. Adapts detection thresholds dynamically rather than maintaining compatibility lists.
- Physics simulation runs a per-player movement simulation accounting for active effects, enchants, and environmental conditions. Flags deviations from expected behavior, not the average hardcoded speed caps. (this took hours for me to make.)
- Transaction-based latency tracks per-player RTT at the connection level. Uses this to adjust reach, velocity, and timing checks, preventing false positives on high-ping players.
- Server-lag resilience all checks skip when server tick time exceeds 100ms or individual player latency spikes.
27 Active Checks
| Package |
Checks |
| Movement |
Speed, Flight, Phase (200-tick grace), NoFall, Timer (1.5s window, 2.5x ratio), Velocity, Jesus, Elytra, Vehicle |
| Combat |
Reach, AutoClicker, AttackCooldown, AutoBlock (use-item→attack within 50ms), HitBox (entity bounding box ≥4.5) |
| Inventory |
Dupe, Container (slot bounds + DataValidator NBT validation), CreativeMatch (creative-spawned item validation) |
| Protocol |
BadPackets (NaN/Infinite/pitch bounds), PingSpoof (200-tick grace, lag-adaptive), PacketOrder (attack/swing order + dig state machine), PayloadRate (10/sec custom payloads) |
| World |
Scaffold, FastBreak (per-block tracking, ABORT/START sequences), FastPlace (30ms interval), Nuker (ray-trace LoS + pattern detection) |
Every check is configurable per-check: enabled, maxVl, and punishment (kick/ban/alert).
Mod-Aware Architecture
BeansAC does not hardcode compatibility. At startup:
- RegistryScanner iterates all Forge registries (items, blocks, enchantments, mob effects, entities). Caches hashes for subsequent boots.
- MovementSimulation computes per-player max speed by scanning their active effects and worn enchants at runtime so modded effects automatically expand the envelope.
- PossibilityMap flags unknown enchants/effects and applies permissive multipliers rather than false-flagging.
- SandboxManager (optional) spins up headless Forge JVMs when uncertain behavior is detected, testing packets against actual mod code.
Data Validation
The DataValidator singleton validates all item NBT entering the server through any path:
- Container clicks (
ServerboundContainerClickPacket)
- Creative inventory (
ServerboundSetCreativeModeSlotPacket)
- Book editing (
ServerboundEditBookPacket — page count, page length, control chars)
- Anvil renaming (
ServerboundRenameItemPacket — name length)
- Enchantment registration and level sanity
- NBT depth limits (prevents recursive tag bombs)
- Firework effect count, skull texture size
False-Positive Resistance
BeansAC prioritizes false-negative over false-positive. Key mitigations:
- Thread safety —
PacketInterceptor.onInboundPacket() and onOutboundPacket() guard with server.isSameThread(). Prevents state corruption from Netty IO threads.
- Server-lag skip —
CheckManager.runAll() returns early when server.getAverageTickTime() > 100ms or per-player latency spikes.
- Grace periods — PhaseCheck waits 200 ticks after spawn/teleport. PingSpoofCheck waits 200 ticks. AutoClickerCheck requires 12+ samples.
- RTT compensation — Reach, AttackCooldown, and Velocity checks account for per-player smoothed RTT.
- VL decay — Violation levels decay by 1 every server tick, preventing accumulated false-flag punishments.
- Modded item tolerance — ElytraCheck accepts any non-vanilla item in the chest slot as a potential elytra, not just
minecraft:elytra.
- Collision-based block detection — PhaseCheck uses
getCollisionShape().isEmpty() instead of a hardcoded whitelist, adapting to any non-solid block from any mod.
Performance
- O(1) state history via circular buffer (no array copies)
- Per-player CompensatedWorld using
AtomicReferenceArray backends
- CheckManager uses efficient class-based dispatch
- Lightweight per-tick state sync
Configuration
TOML-based (config/beansac.toml). Three-phase load: define all values via ForgeConfigSpec.Builder, load file via CommentedFileConfig, then construct immutable config objects. Anti-Xray, sandbox, latency, and webhook sections available.
Cancellation Wiring
All checks that call requestCancel() are wired to the mixin layer and actually cancel the packet:
- ReachCheck cancels
handleInteract, handleUseItemOn, handlePlayerAction via ReachCheck.validate() return value
- NukerCheck cancels
handlePlayerAction via consumeCancel()
- FastBreakCheck cancels
handlePlayerAction via consumeCancel()
- ScaffoldCheck cancels
handleUseItemOn via consumeCancel()
- FastPlaceCheck cancels
handleUseItemOn via consumeCancel()
- AutoBlockCheck cancels
handleInteract via consumeCancel()
- HitBoxCheck cancels
handleInteract via consumeCancel()
- ContainerCheck cancels
handleContainerClick via consumeCancel()
- CreativeMatchCheck cancels
handleSetCreativeModeSlot via consumeCancel()
- PacketOrderCheck cancels
handlePlayerAction via consumeCancel()
- PayloadRateCheck cancels
handleCustomPayload via consumeCancel()
All cancellation paths trigger a resyncBlock() to prevent ghost-block desyncs.
Client Brand Detection
Parses the minecraft:brand payload string and detects known clients (forge, fabric, lunar, badlion, wurst, FastMath, cheat keywords). Shown per-player via /beansac debug.
Dependencies:
- Minecraft Forge, Java 17
Top4eat21's topeatLib
Commands
| Command |
Description |
/beansac alerts |
Toggle live alerts |
/beansac vl <player> |
Show violation levels |
/beansac checks |
List all checks with status |
/beansac debug <player> |
Show client brand + detected features |
License
12Tae12 Protective License, see here.
评论 0
登录后参与评分
还没有评论,来抢沙发吧