Revue de securite du commit F06. 114 tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
132 lignes
5.6 KiB
Java
132 lignes
5.6 KiB
Java
package com.gastinelgarde;
|
|
|
|
import com.gastinelgarde.core.EtatJoueur;
|
|
import com.gastinelgarde.core.KillauraAngle;
|
|
import com.gastinelgarde.core.Sanction;
|
|
import com.gastinelgarde.core.TraceLigne;
|
|
import com.gastinelgarde.core.Verdict;
|
|
import java.util.List;
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.phys.AABB;
|
|
import net.minecraft.world.phys.Vec3;
|
|
import net.neoforged.bus.api.EventPriority;
|
|
import net.neoforged.bus.api.SubscribeEvent;
|
|
import net.neoforged.neoforge.common.util.FakePlayer;
|
|
import net.neoforged.neoforge.event.entity.living.LivingKnockBackEvent;
|
|
import net.neoforged.neoforge.event.entity.living.LivingEntityUseItemEvent;
|
|
import net.neoforged.neoforge.event.entity.player.AttackEntityEvent;
|
|
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
|
|
import net.neoforged.neoforge.event.level.ExplosionKnockbackEvent;
|
|
import net.neoforged.neoforge.event.server.ServerStartingEvent;
|
|
import net.neoforged.neoforge.event.server.ServerStoppedEvent;
|
|
import net.neoforged.neoforge.event.tick.ServerTickEvent;
|
|
|
|
/** Collecte des faits côté serveur (D3) : coups, déconnexions, téléportations, reculs réels, durée des ticks. */
|
|
public final class GardeEvents {
|
|
|
|
private static long debutTickNs;
|
|
|
|
private GardeEvents() { }
|
|
|
|
@SubscribeEvent
|
|
public static void onServerStarting(ServerStartingEvent event) {
|
|
Garde.demarrer();
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public static void onServerStopped(ServerStoppedEvent event) {
|
|
Garde.arreter();
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public static void onTickPre(ServerTickEvent.Pre event) {
|
|
debutTickNs = System.nanoTime();
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public static void onTickPost(ServerTickEvent.Post event) {
|
|
long duree = System.nanoTime() - debutTickNs;
|
|
Garde.noterTickServeur(event.getServer(), duree);
|
|
if (event.getServer().getTickCount() % 20 == 0) Garde.flushTraces();
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public static void onAttaque(AttackEntityEvent event) {
|
|
if (!(event.getEntity() instanceof ServerPlayer p) || p instanceof FakePlayer) return;
|
|
if (Garde.estExempteManuellement(p.getUUID())) return;
|
|
|
|
Entity cible = event.getTarget();
|
|
int tick = p.server.getTickCount();
|
|
EtatJoueur etat = Garde.etat(p, true);
|
|
|
|
AABB bb = cible.getBoundingBox();
|
|
Vec3 oeil = p.getEyePosition();
|
|
Vec3 regard = p.getLookAngle();
|
|
double excedent = KillauraAngle.excedentDegres(oeil.x, oeil.y, oeil.z, regard.x, regard.y, regard.z,
|
|
bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ);
|
|
boolean visible = p.hasLineOfSight(cible);
|
|
|
|
List<Verdict> verdicts = Garde.moteur().attaque(p.getUUID(), tick * 50L, etat, excedent, cible.getId(), visible);
|
|
|
|
if (Garde.tracesEnCours()) {
|
|
Garde.tracer(new TraceLigne(tick, p.getGameProfile().getName(), "atk", p.getX(), p.getY(), p.getZ(),
|
|
0, 0, 0, p.onGround(), p.onGround(), TraceLigne.masque(etat), cible.getId(), excedent,
|
|
visible ? null : "non-visible"));
|
|
}
|
|
|
|
Sanction s = Garde.traiter(p, verdicts);
|
|
if (s.ordinal() >= Sanction.SETBACK.ordinal()) {
|
|
event.setCanceled(true); // le « retour en arrière » d'un coup : il est simplement annulé
|
|
if (s == Sanction.EXPULSION) Garde.appliquerSanctionMouvement(p, s, verdicts);
|
|
}
|
|
}
|
|
|
|
/** F04 : seul un trident Impulsion relâché après charge ouvre la tolérance riptide (pas le trident tenu). */
|
|
@SubscribeEvent
|
|
public static void onRelache(LivingEntityUseItemEvent.Stop event) {
|
|
if (event.getEntity() instanceof ServerPlayer p && !(p instanceof FakePlayer)) {
|
|
Garde.noterRelache(p, event.getItem(), event.getDuration());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* F06 : la grâce de recul ne s'ouvre que si une vitesse est réellement donnée au joueur. Un dégât sans recul
|
|
* (feu, cactus, poison, wither, faim, chute : tag vanilla no_knockback) ne déclenche pas knockback().
|
|
*/
|
|
@SubscribeEvent(priority = EventPriority.LOWEST)
|
|
public static void onRecul(LivingKnockBackEvent event) {
|
|
if (event.isCanceled() || event.getStrength() <= 0.0F) return;
|
|
if (event.getEntity() instanceof ServerPlayer p && !(p instanceof FakePlayer)) Garde.noterRecul(p, false);
|
|
}
|
|
|
|
/** Explosion, charge de vent (Wind Charge) : poussée vers le joueur. Celle qu'il s'inflige est limitée (GraceRecul). */
|
|
@SubscribeEvent(priority = EventPriority.LOWEST)
|
|
public static void onPousseeExplosion(ExplosionKnockbackEvent event) {
|
|
if (event.getKnockbackVelocity().lengthSqr() <= 1.0E-6) return;
|
|
if (!(event.getAffectedEntity() instanceof ServerPlayer p) || p instanceof FakePlayer) return;
|
|
boolean auto = event.getExplosion().getIndirectSourceEntity() == p || event.getExplosion().getDirectSourceEntity() == p;
|
|
Garde.noterRecul(p, auto);
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public static void onConnexion(PlayerEvent.PlayerLoggedInEvent event) {
|
|
if (event.getEntity() instanceof ServerPlayer p) Garde.noterTeleport(p);
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public static void onDeconnexion(PlayerEvent.PlayerLoggedOutEvent event) {
|
|
Garde.joueurParti(event.getEntity().getUUID());
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public static void onChangementDimension(PlayerEvent.PlayerChangedDimensionEvent event) {
|
|
if (event.getEntity() instanceof ServerPlayer p) Garde.noterTeleport(p);
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public static void onReapparition(PlayerEvent.PlayerRespawnEvent event) {
|
|
if (event.getEntity() instanceof ServerPlayer p) Garde.noterTeleport(p);
|
|
}
|
|
}
|