-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
添加一个实验性的默认关闭的反作弊。目前仅包含飞行检查。 已知误判:游泳、跳跃提升。
- Loading branch information
Showing
9 changed files
with
195 additions
and
31 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/main/java/top/infsky/timerecorder/anticheat/Check.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package top.infsky.timerecorder.anticheat; | ||
|
||
import lombok.Getter; | ||
import top.infsky.timerecorder.data.PlayerData; | ||
import top.infsky.timerecorder.log.LogUtils; | ||
|
||
@Getter | ||
public abstract class Check { | ||
public String checkName; | ||
public PlayerData player; | ||
|
||
public Check(String checkName, PlayerData player) { | ||
this.checkName = checkName; | ||
this.player = player; | ||
} | ||
|
||
public final void flag() { | ||
assert player.antiCheat != null; | ||
player.antiCheat.violations++; | ||
LogUtils.alert(player.getName(), checkName); | ||
} | ||
|
||
public final void flag(String extraMsg) { | ||
assert player.antiCheat != null; | ||
player.antiCheat.violations++; | ||
LogUtils.alert(player.getName(), checkName, extraMsg); | ||
} | ||
|
||
public abstract void _onTick(); | ||
|
||
public void update() { | ||
if (player == null) return; | ||
_onTick(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/top/infsky/timerecorder/anticheat/CheckManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package top.infsky.timerecorder.anticheat; | ||
|
||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.NotNull; | ||
import top.infsky.timerecorder.anticheat.checks.FlightA; | ||
import top.infsky.timerecorder.data.PlayerData; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class CheckManager { | ||
public List<Check> checks = new ArrayList<>(); | ||
public double violations = 0; | ||
public CheckManager(List<Check> checks) { | ||
this.checks.addAll(checks); | ||
} | ||
|
||
@Contract("_ -> new") | ||
public static @NotNull CheckManager create(PlayerData playerData) { | ||
return new CheckManager(List.of( | ||
new FlightA(playerData) | ||
)); | ||
} | ||
|
||
public void update() { | ||
for (Check check : checks) { | ||
check.update(); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/top/infsky/timerecorder/anticheat/checks/FlightA.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package top.infsky.timerecorder.anticheat.checks; | ||
|
||
import net.minecraft.world.phys.Vec3; | ||
import top.infsky.timerecorder.anticheat.Check; | ||
import top.infsky.timerecorder.config.ModConfig; | ||
import top.infsky.timerecorder.data.PlayerData; | ||
|
||
public class FlightA extends Check { | ||
public Vec3 lastPos; | ||
public Vec3 lastPos2; | ||
public Vec3 lastOnGroundPos; | ||
public short disableTick = 0; | ||
|
||
public FlightA(PlayerData player) { | ||
super("FlightA", player); | ||
assert player.player != null; | ||
lastPos = player.player.position(); | ||
} | ||
|
||
@Override | ||
public void _onTick() { | ||
assert player.player != null; | ||
|
||
// fix jump | ||
if (player.player.onGround()) { | ||
lastOnGroundPos = player.player.position(); | ||
disableTick = 8; | ||
} | ||
|
||
if (!player.player.onGround() && disableTick > 0 | ||
&& player.player.position().y() - lastOnGroundPos.y() < 1.25219 + ModConfig.INSTANCE.getAntiCheat().getThreshold()) { | ||
disableTick--; | ||
} else if (lastPos2 != null && !player.player.onGround()) { | ||
disableTick = 0; | ||
if (lastPos.y() - player.player.position().y() < ModConfig.INSTANCE.getAntiCheat().getThreshold() && | ||
lastPos2.y() - lastPos.y() <= ModConfig.INSTANCE.getAntiCheat().getThreshold()) { | ||
flag(String.format("Pos:%s OnGround:%s", player.player.position(), player.player.onGround())); | ||
} | ||
} | ||
lastPos2 = lastPos; | ||
lastPos = player.player.position(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/top/infsky/timerecorder/command/AlertCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package top.infsky.timerecorder.command; | ||
|
||
import com.mojang.brigadier.context.CommandContext; | ||
import net.minecraft.ChatFormatting; | ||
import net.minecraft.commands.CommandSourceStack; | ||
import net.minecraft.network.chat.Component; | ||
import org.jetbrains.annotations.NotNull; | ||
import top.infsky.timerecorder.config.ModConfig; | ||
|
||
import java.util.Objects; | ||
|
||
public class AlertCommand { | ||
public static int execute(@NotNull CommandContext<CommandSourceStack> context) { | ||
if (context.getSource().isPlayer()) { | ||
ModConfig.INSTANCE.getAntiCheat().getAllowAlertPlayers().add(Objects.requireNonNull(context.getSource().getPlayer()).getStringUUID()); | ||
ModConfig.INSTANCE.save(); | ||
context.getSource().sendSystemMessage(Component.literal("警报已开启").withStyle(ChatFormatting.AQUA).withStyle(ChatFormatting.BOLD)); | ||
} | ||
return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,40 @@ | ||
package top.infsky.timerecorder.log; | ||
|
||
import lombok.Getter; | ||
import net.minecraft.network.chat.Component; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import top.infsky.timerecorder.Utils; | ||
import top.infsky.timerecorder.config.ModConfig; | ||
|
||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
@Getter | ||
public class LogUtils { | ||
public static final Logger LOGGER = LoggerFactory.getLogger("TimeRecorder"); // 抄代码抄的 | ||
|
||
public static void alert(String player, String module, String extraMsg) { | ||
// LOGGER.info(String.format("§b§lTR§r§l> §r%s 触发了 %s | %s", player, module, extraMsg)); | ||
LOGGER.info(String.format("TR> %s 触发了 %s | %s", player, module, extraMsg)); | ||
ModConfig.INSTANCE.getAntiCheat().getAllowAlertPlayers().forEach(string -> { | ||
assert Utils.getSERVER() != null; | ||
try { | ||
Objects.requireNonNull(Utils.getSERVER().getPlayerList().getPlayer(UUID.fromString(string))).sendSystemMessage(Component.literal( | ||
String.format("§b§lTR§r§l> §r%s 触发了 %s | %s", player, module, extraMsg) | ||
)); | ||
} catch (NullPointerException ignored) {} | ||
}); | ||
} | ||
|
||
public static void alert(String player, String module) { | ||
// LOGGER.info(String.format("§b§lTR§r§l> §r%s 触发了 %s", player, module)); | ||
LOGGER.info(String.format("TR> %s 触发了 %s", player, module)); | ||
ModConfig.INSTANCE.getAntiCheat().getAllowAlertPlayers().forEach(string -> { | ||
assert Utils.getSERVER() != null; | ||
try { | ||
Objects.requireNonNull(Utils.getSERVER().getPlayerList().getPlayer(UUID.fromString(string))).sendSystemMessage(Component.literal( | ||
String.format("§b§lTR§r§l> §r%s 触发了 %s", player, module) | ||
)); | ||
} catch (NullPointerException ignored) {} | ||
}); | ||
} | ||
} |