Comparer les révisions
11
Révisions
| Auteur | SHA1 | Date | ||
|---|---|---|---|---|
| ||||
|
|
e87b8374ef | |||
|
|
26d610f79a | |||
|
|
59dea0d436 | |||
|
|
40c89825de | |||
|
|
c92ebb055a | |||
|
|
1116f6137b | |||
|
|
c5bd0265f6 | |||
|
|
22ccc5fa59 | |||
|
|
334cc5b45c | |||
|
|
80c9748a23 | |||
|
|
c7b130ec1c | |||
Aucun fichier ne correspond à votre recherche
@@ -1,5 +1,19 @@
|
|||||||
# Journal des versions
|
# Journal des versions
|
||||||
|
|
||||||
|
## 0.4.0 (non publiée, branche feat/suspicion-score, dérivée de release/0.3.1 = jar déployé)
|
||||||
|
|
||||||
|
Testé hors jeu seulement (JUnit) ; rien n'a été essayé sur un serveur Minecraft. Aucun mode existant n'est modifié.
|
||||||
|
- Score de suspicion 0-100 par joueur (section `[suspicion]`) : journal dès 25, message aux ops dès 50, dès 75 simple
|
||||||
|
proposition « suspect_2 à valider dans le Portail ». Jamais de sanction ni de bannissement à partir du score.
|
||||||
|
Historique des incidents par UUID sur 7 jours dans `gastinelgarde-suspicion/incidents.csv`. `/garde status <joueur>`
|
||||||
|
affiche le score. Pas de signalement au Hub (absent de cette base, voir le rapport).
|
||||||
|
- Vol : flottement prolongé (`volFlottementTicks` = 80, équivalent du « kicked for floating too long » vanilla), pour
|
||||||
|
pouvoir passer `allow-flight=true`. Insensible aux paquets à 0 tick et aux trous de ticks.
|
||||||
|
- Nouveaux contrôles, OBSERVE par défaut : `elytres` (Elytra Hack), `velocite` (Anti Knockback / Anti Push),
|
||||||
|
`auto-totem` (section `[nouveauxControles]`).
|
||||||
|
- Correctif : le motif écrit pour une sanction (journal, message d'expulsion) est celui du verdict qui sanctionne,
|
||||||
|
plus celui du premier verdict de la liste.
|
||||||
|
|
||||||
## 0.3.1 (16/10/2026)
|
## 0.3.1 (16/10/2026)
|
||||||
|
|
||||||
Version de correctifs. Les modes OBSERVE / ENFORCE de chaque contrôle sont inchangés (aucun défaut de mode modifié).
|
Version de correctifs. Les modes OBSERVE / ENFORCE de chaque contrôle sont inchangés (aucun défaut de mode modifié).
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
org.gradle.jvmargs=-Xmx2G
|
org.gradle.jvmargs=-Xmx2G
|
||||||
org.gradle.parallel=true
|
org.gradle.parallel=true
|
||||||
|
|
||||||
mod_version=0.3.1
|
mod_version=0.4.2
|
||||||
mod_group_id=com.gastinelgarde
|
mod_group_id=com.gastinelgarde
|
||||||
mod_id=gastinelgarde
|
mod_id=gastinelgarde
|
||||||
|
|
||||||
|
|||||||
@@ -115,6 +115,27 @@ final class Cablage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- 0.4.0 : grace de propulsion d'une fusee (plane en elytres) ---
|
||||||
|
|
||||||
|
/** Ticks de marge après la fin de vie de la fusée (dernier tick de poussée, retard d'état). */
|
||||||
|
static final int MARGE_FUSEE_TICKS = 20;
|
||||||
|
/** 0.4.1 : duree de vie vanilla d'une fusee : 10 x (1 + duree de vol) + 0..11, soit 20 a 51 ticks pour les durees 1 a 3. */
|
||||||
|
static final int VIE_FUSEE_MAX = 60;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grâce de propulsion accordée à l'apparition d'une fusée : seulement si elle est réellement attachée au joueur
|
||||||
|
* (propulsion en plané, pas une fusée d'arbalète ou posée au sol), si le joueur plane à cet instant, et si elle
|
||||||
|
* ne vient pas d'être rechargée depuis le disque. Durée : vie restante réelle de la fusée + marge, au lieu de 6 s
|
||||||
|
* fixes (un tricheur qui tire une fusée toutes les quelques secondes n'obtient jamais plus que la vie de la fusée).
|
||||||
|
*
|
||||||
|
* @return nombre de ticks de grâce (0 = aucune)
|
||||||
|
*/
|
||||||
|
static int graceFusee(boolean attacheeAuJoueur, boolean joueurPlane, boolean rechargeeDuDisque, int vie, int dureeDeVie) {
|
||||||
|
if (!attacheeAuJoueur || !joueurPlane || rechargeeDuDisque) return 0;
|
||||||
|
int restant = Math.max(0, dureeDeVie - Math.max(0, vie));
|
||||||
|
return Math.min(restant, VIE_FUSEE_MAX) + MARGE_FUSEE_TICKS;
|
||||||
|
}
|
||||||
|
|
||||||
// --- Position de retour (C3) ---
|
// --- Position de retour (C3) ---
|
||||||
|
|
||||||
/** apresMouvement : la position de ce paquet devient-elle la position de retour ? */
|
/** apresMouvement : la position de ce paquet devient-elle la position de retour ? */
|
||||||
@@ -138,9 +159,23 @@ final class Cablage {
|
|||||||
void journal(String ligne);
|
void journal(String ligne);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Motif écrit pour une sanction : le contrôle du verdict qui l'a déclenchée (applicable == sanction). Avant 0.4.0
|
||||||
|
* c'était le premier de la liste, donc un contrôle en OBSERVE (vitesse) pouvait être accusé à la place du vol.
|
||||||
|
* À défaut, le verdict le plus sévère, puis « anti-triche ».
|
||||||
|
*/
|
||||||
|
static String raison(List<Verdict> verdicts, Sanction s) {
|
||||||
|
Verdict retenu = null;
|
||||||
|
for (Verdict v : verdicts) {
|
||||||
|
if (v.applicable() == s) return v.controle().id();
|
||||||
|
if (retenu == null || v.applicable().ordinal() > retenu.applicable().ordinal()) retenu = v;
|
||||||
|
}
|
||||||
|
return retenu == null ? "anti-triche" : retenu.controle().id();
|
||||||
|
}
|
||||||
|
|
||||||
/** Expulsion à usage unique (C4) ; setback vers la position de retour de la même dimension, puis remise à zéro (C2). */
|
/** Expulsion à usage unique (C4) ; setback vers la position de retour de la même dimension, puis remise à zéro (C2). */
|
||||||
static void appliquerSanction(Moteur moteur, Joueur p, Sanction s, List<Verdict> verdicts) {
|
static void appliquerSanction(Moteur moteur, Joueur p, Sanction s, List<Verdict> verdicts) {
|
||||||
String raison = verdicts.isEmpty() ? "anti-triche" : verdicts.get(0).controle().id();
|
String raison = raison(verdicts, s);
|
||||||
if (s == Sanction.EXPULSION) {
|
if (s == Sanction.EXPULSION) {
|
||||||
// C4 (16/10) : une seule expulsion par incident (avant : 344 disconnect en 18 s). Jamais de bannissement.
|
// C4 (16/10) : une seule expulsion par incident (avant : 344 disconnect en 18 s). Jamais de bannissement.
|
||||||
if (!moteur.expulser(p.id(), p.tick() * 50L)) return;
|
if (!moteur.expulser(p.id(), p.tick() * 50L)) return;
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ public final class Garde {
|
|||||||
/** Marques propres à un joueur, côté adaptateur (ticks du serveur). */
|
/** Marques propres à un joueur, côté adaptateur (ticks du serveur). */
|
||||||
private static final class Marques {
|
private static final class Marques {
|
||||||
int teleportTick = Integer.MIN_VALUE;
|
int teleportTick = Integer.MIN_VALUE;
|
||||||
|
/** 0.4.0 : jusqu'à ce tick, une fusée a propulsé le joueur (plané non contrôlé). */
|
||||||
|
int propulsionJusquaTick = Integer.MIN_VALUE;
|
||||||
int reculTick = Integer.MIN_VALUE;
|
int reculTick = Integer.MIN_VALUE;
|
||||||
int dernierVerdictTick = Integer.MIN_VALUE;
|
int dernierVerdictTick = Integer.MIN_VALUE;
|
||||||
int dernierTraceTick = Integer.MIN_VALUE;
|
int dernierTraceTick = Integer.MIN_VALUE;
|
||||||
@@ -143,6 +145,13 @@ public final class Garde {
|
|||||||
Files.createDirectories(journal.getParent());
|
Files.createDirectories(journal.getParent());
|
||||||
traces = new TraceFichier(jeu.resolve("gastinelgarde-traces"), GardeSpec.tracesJours(), GardeSpec.tracesTailleOctets());
|
traces = new TraceFichier(jeu.resolve("gastinelgarde-traces"), GardeSpec.tracesJours(), GardeSpec.tracesTailleOctets());
|
||||||
tracesEnCours = GardeSpec.tracesActives();
|
tracesEnCours = GardeSpec.tracesActives();
|
||||||
|
// Historique de suspicion : même dossier de jeu que les traces et les journaux (voir HistoriqueSuspicion).
|
||||||
|
try {
|
||||||
|
MOTEUR.historique().ouvrir(jeu.resolve("gastinelgarde-suspicion").resolve("incidents.csv"),
|
||||||
|
System.currentTimeMillis(), CONFIG.suspicionHistoriqueJours);
|
||||||
|
} catch (IOException | RuntimeException e) {
|
||||||
|
GastinelGarde.LOGGER.warn("[GastinelGarde] historique de suspicion illisible, repart à vide : {}", e.toString());
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
GastinelGarde.LOGGER.error("[GastinelGarde] Impossible d'ouvrir le dossier de traces", e);
|
GastinelGarde.LOGGER.error("[GastinelGarde] Impossible d'ouvrir le dossier de traces", e);
|
||||||
traces = null;
|
traces = null;
|
||||||
@@ -335,6 +344,44 @@ public final class Garde {
|
|||||||
if (m.graceRecul.recul(tick, autoInflige)) m.reculTick = tick;
|
if (m.graceRecul.recul(tick, autoInflige)) m.reculTick = tick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Fusée de feu d'artifice tirée par ce joueur (propulsion en plané) : le plané n'est pas contrôlé pendant 6 s. */
|
||||||
|
public static void noterFusee(ServerPlayer p, int ticks) {
|
||||||
|
if (!surThreadServeur(p)) return;
|
||||||
|
Marques m = marques(p.getUUID());
|
||||||
|
m.propulsionJusquaTick = Math.max(m.propulsionJusquaTick, p.server.getTickCount() + ticks);
|
||||||
|
MOTEUR.nouvelleFusee(p.getUUID());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 0.4.0 : recul appliqué par le serveur (direction du déplacement attendu, force avant résistance). */
|
||||||
|
public static void noterVelocite(ServerPlayer p, double dirX, double dirZ, double force) {
|
||||||
|
if (!surThreadServeur(p)) return;
|
||||||
|
double resistance = p.getAttributeValue(net.minecraft.world.entity.ai.attributes.Attributes.KNOCKBACK_RESISTANCE);
|
||||||
|
// Le joueur est-il libre de reculer ? Boîte déplacée de 0,6 puis 1,2 bloc dans le sens du recul : un mur, un trou
|
||||||
|
// d'un bloc ou un plafond bas (coup d'un tiers qui coince le joueur) annulent la mesure.
|
||||||
|
double norme = Math.hypot(dirX, dirZ);
|
||||||
|
boolean libre = norme > 1e-6;
|
||||||
|
if (libre) {
|
||||||
|
net.minecraft.world.phys.AABB b = p.getBoundingBox();
|
||||||
|
double ux = dirX / norme, uz = dirZ / norme;
|
||||||
|
libre = p.level().noCollision(p, b.move(ux * 0.6, 0, uz * 0.6)) && p.level().noCollision(p, b.move(ux * 1.2, 0, uz * 1.2));
|
||||||
|
}
|
||||||
|
MOTEUR.reculApplique(p.getUUID(), p.server.getTickCount() * 50L, dirX, dirZ,
|
||||||
|
force * Math.max(0.0, 1.0 - resistance), libre);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 0.4.0 : un totem d'immortalité vient d'éclater (hand = main qui le tenait). */
|
||||||
|
public static void noterTotem(ServerPlayer p, net.minecraft.world.InteractionHand hand) {
|
||||||
|
if (!surThreadServeur(p)) return;
|
||||||
|
net.minecraft.world.InteractionHand autre = hand == net.minecraft.world.InteractionHand.MAIN_HAND
|
||||||
|
? net.minecraft.world.InteractionHand.OFF_HAND : net.minecraft.world.InteractionHand.MAIN_HAND;
|
||||||
|
boolean reserve = p.getItemInHand(autre).is(Items.TOTEM_OF_UNDYING);
|
||||||
|
MOTEUR.totemEclate(p.getUUID(), p.server.getTickCount() * 50L, reserve);
|
||||||
|
// 0.4.1 : trace de diagnostic (rare : un totem qui eclate) ; explique l'absence de ligne auto-totem ensuite.
|
||||||
|
ecrireJournal(String.format("%s auto-totem eclatement main=%s reserve=%s mode=%s expulse=%s exempte=%s",
|
||||||
|
p.getGameProfile().getName(), hand, reserve, CONFIG.mode(Controle.AUTO_TOTEM),
|
||||||
|
MOTEUR.estExpulse(p.getUUID()), estExempteManuellement(p.getUUID())));
|
||||||
|
}
|
||||||
|
|
||||||
public static void noterTickServeur(MinecraftServer server, long dureeNs) {
|
public static void noterTickServeur(MinecraftServer server, long dureeNs) {
|
||||||
double ms = dureeNs / 1_000_000.0;
|
double ms = dureeNs / 1_000_000.0;
|
||||||
if (ms > 250.0) gelTick = server.getTickCount();
|
if (ms > 250.0) gelTick = server.getTickCount();
|
||||||
@@ -405,6 +452,7 @@ public final class Garde {
|
|||||||
.ticksDepuisGel(depuis(tick, gelTick))
|
.ticksDepuisGel(depuis(tick, gelTick))
|
||||||
.tps(tpsEstime)
|
.tps(tpsEstime)
|
||||||
.pingMs(p.connection.latency())
|
.pingMs(p.connection.latency())
|
||||||
|
.propulsionRecente(tick <= m.propulsionJusquaTick)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -524,9 +572,31 @@ public final class Garde {
|
|||||||
}
|
}
|
||||||
if (v.notifier()) alerterOps(p, v);
|
if (v.notifier()) alerterOps(p, v);
|
||||||
}
|
}
|
||||||
|
reagirSuspicion(p);
|
||||||
return Verdict.pire(verdicts);
|
return Verdict.pire(verdicts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Score de suspicion (0.4.0) : journal dès « à surveiller », message aux ops dès « suspect ». À « suspect fort »,
|
||||||
|
* seulement une proposition de sanction à valider dans le Portail : le mod ne sanctionne jamais à partir du score.
|
||||||
|
*/
|
||||||
|
private static void reagirSuspicion(ServerPlayer p) {
|
||||||
|
Moteur.AlerteSuspicion a = MOTEUR.alerteSuspicion(p.getUUID(), System.currentTimeMillis());
|
||||||
|
if (a == null) return;
|
||||||
|
String nom = p.getGameProfile().getName();
|
||||||
|
ecrireJournal(String.format("SUSPICION %s (%s) score=%d niveau=%s incidents7j=%d contributions=[%s]",
|
||||||
|
nom, p.getUUID(), a.score(), a.niveau(), a.incidents(), a.controles()));
|
||||||
|
if (a.niveau().ordinal() < com.gastinelgarde.core.Suspicion.Niveau.SUSPECT.ordinal()) return;
|
||||||
|
String texte = a.niveau() == com.gastinelgarde.core.Suspicion.Niveau.SUSPECT_FORT
|
||||||
|
? String.format("[Garde] %s : suspect fort (score %d). Proposition de sanction suspect_2, à valider dans le Portail.",
|
||||||
|
nom, a.score())
|
||||||
|
: String.format("[Garde] %s : suspect (score %d, %d incident(s) sur 7 jours).", nom, a.score(), a.incidents());
|
||||||
|
Component msg = Component.literal(texte).withStyle(ChatFormatting.RED);
|
||||||
|
for (ServerPlayer op : p.server.getPlayerList().getPlayers()) {
|
||||||
|
if (op.hasPermissions(2) && alertesActivesPour(op.getUUID())) op.sendSystemMessage(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void alerterOps(ServerPlayer cible, Verdict v) {
|
private static void alerterOps(ServerPlayer cible, Verdict v) {
|
||||||
Component msg = Component.literal(String.format("[Garde] %s : %s VL=%.1f (%s, %s)",
|
Component msg = Component.literal(String.format("[Garde] %s : %s VL=%.1f (%s, %s)",
|
||||||
cible.getGameProfile().getName(), v.controle().id(), v.vl(), v.mode(), v.applicable()))
|
cible.getGameProfile().getName(), v.controle().id(), v.vl(), v.mode(), v.applicable()))
|
||||||
@@ -619,6 +689,24 @@ public final class Garde {
|
|||||||
m.oeilAvant = m.oeilDernier;
|
m.oeilAvant = m.oeilDernier;
|
||||||
m.oeilDernier = new double[] {oeil.x, oeil.y, oeil.z};
|
m.oeilDernier = new double[] {oeil.x, oeil.y, oeil.z};
|
||||||
}
|
}
|
||||||
|
// 0.4.0 : recul mesuré (anti-recul) et totem remis en main (auto-totem), sur les mêmes paquets.
|
||||||
|
if (!estExempteManuellement(p.getUUID()) && (CONFIG.mode(Controle.VELOCITE) != Mode.OFF
|
||||||
|
|| CONFIG.mode(Controle.AUTO_TOTEM) != Mode.OFF)) {
|
||||||
|
EtatJoueur etatSup = etat(p, true);
|
||||||
|
long maintenant = tick * 50L;
|
||||||
|
if (m.mouvementTick != Integer.MIN_VALUE) {
|
||||||
|
// milieuSpecial toujours calculé ici, indépendamment de em (nul quand vol/vitesse/no-fall sont coupés).
|
||||||
|
List<Verdict> v = MOTEUR.mesureRecul(p.getUUID(), maintenant, etatSup, p.getX() - m.mouvementX,
|
||||||
|
p.getZ() - m.mouvementZ, milieuSpecial(p, m, tick), (ux, uz) -> !p.level().noCollision(p,
|
||||||
|
p.getBoundingBox().move(ux * 0.3, 0, uz * 0.3)));
|
||||||
|
Sanction sv = traiter(p, v); // 0.4.2 : setback (retour en arrière) ou expulsion en ENFORCE
|
||||||
|
if (Cablage.sanctionDeMouvement(sv)) appliquerSanctionMouvement(p, sv, v);
|
||||||
|
}
|
||||||
|
boolean totem = p.getMainHandItem().is(Items.TOTEM_OF_UNDYING) || p.getOffhandItem().is(Items.TOTEM_OF_UNDYING);
|
||||||
|
List<Verdict> vt = MOTEUR.totemEnMain(p.getUUID(), maintenant, etatSup, totem);
|
||||||
|
Sanction st = traiter(p, vt); // 0.4.2 : expulsion en ENFORCE (le palier SETBACK reste une alerte)
|
||||||
|
if (st == Sanction.EXPULSION) appliquerSanctionMouvement(p, st, vt);
|
||||||
|
}
|
||||||
m.mouvementTick = tick;
|
m.mouvementTick = tick;
|
||||||
m.mouvementX = p.getX();
|
m.mouvementX = p.getX();
|
||||||
m.mouvementY = p.getY();
|
m.mouvementY = p.getY();
|
||||||
|
|||||||
@@ -91,6 +91,8 @@ public final class GardeCommands {
|
|||||||
sb.append("\n ").append(k.id()).append(" VL=")
|
sb.append("\n ").append(k.id()).append(" VL=")
|
||||||
.append(String.format(java.util.Locale.ROOT, "%.1f", suivi.vl.valeur(k, now)));
|
.append(String.format(java.util.Locale.ROOT, "%.1f", suivi.vl.valeur(k, now)));
|
||||||
}
|
}
|
||||||
|
sb.append(String.format(java.util.Locale.ROOT, "\n suspicion = %.0f (%s)", Garde.moteur().scoreSuspicion(p.getUUID()),
|
||||||
|
suivi.suspicion.niveau(System.currentTimeMillis())));
|
||||||
if (Garde.estExempteManuellement(p.getUUID())) sb.append("\n (exempté manuellement)");
|
if (Garde.estExempteManuellement(p.getUUID())) sb.append("\n (exempté manuellement)");
|
||||||
ok(ctx, sb.toString());
|
ok(ctx, sb.toString());
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -129,7 +129,11 @@ public final class GardeEvents {
|
|||||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||||
public static void onRecul(LivingKnockBackEvent event) {
|
public static void onRecul(LivingKnockBackEvent event) {
|
||||||
if (event.isCanceled() || event.getStrength() <= 0.0F) return;
|
if (event.isCanceled() || event.getStrength() <= 0.0F) return;
|
||||||
if (event.getEntity() instanceof ServerPlayer p && !(p instanceof FakePlayer)) Garde.noterRecul(p, false);
|
if (event.getEntity() instanceof ServerPlayer p && !(p instanceof FakePlayer)) {
|
||||||
|
Garde.noterRecul(p, false);
|
||||||
|
// Vanilla retire (ratioX, ratioZ) x force à la vitesse du joueur : il part à l'opposé.
|
||||||
|
Garde.noterVelocite(p, -event.getRatioX(), -event.getRatioZ(), event.getStrength());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Explosion, charge de vent (Wind Charge) : poussée vers le joueur. Celle qu'il s'inflige est limitée (GraceRecul). */
|
/** Explosion, charge de vent (Wind Charge) : poussée vers le joueur. Celle qu'il s'inflige est limitée (GraceRecul). */
|
||||||
@@ -139,6 +143,28 @@ public final class GardeEvents {
|
|||||||
if (!(event.getAffectedEntity() instanceof ServerPlayer p) || p instanceof FakePlayer) return;
|
if (!(event.getAffectedEntity() instanceof ServerPlayer p) || p instanceof FakePlayer) return;
|
||||||
boolean auto = event.getExplosion().getIndirectSourceEntity() == p || event.getExplosion().getDirectSourceEntity() == p;
|
boolean auto = event.getExplosion().getIndirectSourceEntity() == p || event.getExplosion().getDirectSourceEntity() == p;
|
||||||
Garde.noterRecul(p, auto);
|
Garde.noterRecul(p, auto);
|
||||||
|
Vec3 v = event.getKnockbackVelocity();
|
||||||
|
Garde.noterVelocite(p, v.x, v.z, Math.hypot(v.x, v.z));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Fusée de feu d'artifice tirée par un joueur : propulsion en plané, donc plané non contrôlé un moment. */
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onFusee(net.neoforged.neoforge.event.entity.EntityJoinLevelEvent event) {
|
||||||
|
if (!(event.getEntity() instanceof net.minecraft.world.entity.projectile.FireworkRocketEntity f)) return;
|
||||||
|
// Champ privé attachedToEntity lu via l'Access Transformer (META-INF/accesstransformer.cfg) : seule une fusée
|
||||||
|
// attachée au joueur le propulse (FireworkRocketEntity.tick), jamais une fusée d'arbalète ou posée au sol.
|
||||||
|
if (f.attachedToEntity instanceof ServerPlayer p && !(p instanceof FakePlayer)) {
|
||||||
|
int ticks = Cablage.graceFusee(true, p.isFallFlying(), event.loadedFromDisk(), f.life, f.lifetime);
|
||||||
|
if (ticks > 0) Garde.noterFusee(p, ticks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Totem éclaté : début de la mesure du délai de remise (auto-totem). */
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onTotem(net.neoforged.neoforge.event.entity.living.LivingUseTotemEvent event) {
|
||||||
|
if (event.getEntity() instanceof ServerPlayer p && !(p instanceof FakePlayer)) {
|
||||||
|
Garde.noterTotem(p, event.getHandHolding());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
|||||||
@@ -51,6 +51,12 @@ public final class GardeSpec {
|
|||||||
private static final ModConfigSpec.IntValue SERIE_PING_MAX;
|
private static final ModConfigSpec.IntValue SERIE_PING_MAX;
|
||||||
private static final ModConfigSpec.IntValue SERIE_PING_MARGE;
|
private static final ModConfigSpec.IntValue SERIE_PING_MARGE;
|
||||||
private static final ModConfigSpec.IntValue TIMER_SOLDE_MAX;
|
private static final ModConfigSpec.IntValue TIMER_SOLDE_MAX;
|
||||||
|
private static final ModConfigSpec.IntValue ELY_MONTEE, ELY_STATIONNAIRE, VEL_FENETRE, VEL_SERIE, TOTEM_DELAI, TOTEM_PING;
|
||||||
|
private static final ModConfigSpec.DoubleValue VEL_RAPPORT, VEL_FORCE, VEL_POINTS, TOTEM_SEUIL_SB, TOTEM_SEUIL_EXP, VEL_SEUIL_SB, VEL_SEUIL_EXP;
|
||||||
|
private static final ModConfigSpec.BooleanValue SUSP_ACTIVE;
|
||||||
|
private static final ModConfigSpec.DoubleValue SUSP_SURVEILLER, SUSP_SUSPECT, SUSP_FORT, SUSP_DEMI_VIE,
|
||||||
|
SUSP_PLAFOND_FIABLE, SUSP_PLAFOND_MOYEN, SUSP_PLAFOND_FAIBLE, SUSP_DIVERSITE_FENETRE;
|
||||||
|
private static final ModConfigSpec.IntValue SUSP_DIVERSITE, SUSP_JOURS, VOL_FLOTTEMENT;
|
||||||
private static final ModConfigSpec.BooleanValue VOL_FENETRE_GLISSANTE;
|
private static final ModConfigSpec.BooleanValue VOL_FENETRE_GLISSANTE;
|
||||||
private static final ModConfigSpec.BooleanValue VITESSE_MOYENNE;
|
private static final ModConfigSpec.BooleanValue VITESSE_MOYENNE;
|
||||||
private static final ModConfigSpec.BooleanValue ELYTRES_STRICTE;
|
private static final ModConfigSpec.BooleanValue ELYTRES_STRICTE;
|
||||||
@@ -155,7 +161,62 @@ public final class GardeSpec {
|
|||||||
.defineInRange("timerSoldeMax", 0, 0, 1000);
|
.defineInRange("timerSoldeMax", 0, 0, 1000);
|
||||||
b.pop();
|
b.pop();
|
||||||
|
|
||||||
|
b.comment("Score de suspicion de 0 à 100 par joueur (0.4.0). INFORMATION POUR LES HUMAINS : aucune sanction n'en découle.",
|
||||||
|
"Chaque contrôle (même en OBSERVE) contribue (VL / seuilExpulsion, au plus 1) x son plafond selon sa fiabilité ;",
|
||||||
|
"le pic décroît avec une demi-vie. Journal dès seuilSurveiller ; message aux ops dès seuilSuspect ;",
|
||||||
|
"dès seuilFort, proposition de sanction suspect_2 à valider dans le Portail (jamais appliquée par le mod).")
|
||||||
|
.push("suspicion");
|
||||||
|
SUSP_ACTIVE = b.define("actif", true);
|
||||||
|
SUSP_SURVEILLER = b.defineInRange("seuilSurveiller", 25.0, 1.0, 100.0);
|
||||||
|
SUSP_SUSPECT = b.defineInRange("seuilSuspect", 50.0, 1.0, 100.0);
|
||||||
|
SUSP_FORT = b.defineInRange("seuilFort", 75.0, 1.0, 100.0);
|
||||||
|
SUSP_DEMI_VIE = b.comment("Demi-vie du score, en minutes de jeu (le suivi est libéré à la déconnexion).")
|
||||||
|
.defineInRange("demiVieMinutes", 10.0, 0.5, 1440.0);
|
||||||
|
SUSP_PLAFOND_FIABLE = b.comment("Plafond de contribution : vol, vitesse, no-fall, portee, hitbox, regularite.")
|
||||||
|
.defineInRange("plafondFiable", 50.0, 0.0, 100.0);
|
||||||
|
SUSP_PLAFOND_MOYEN = b.comment("Plafond : coups-hors-boite, killaura-angle, killaura-cibles, cadence.")
|
||||||
|
.defineInRange("plafondMoyen", 30.0, 0.0, 100.0);
|
||||||
|
SUSP_PLAFOND_FAIBLE = b.comment("Plafond : timer, rotation, attaque-impossible, vehicule-vitesse, vehicule-vol (faux positifs).")
|
||||||
|
.defineInRange("plafondFaible", 15.0, 0.0, 100.0);
|
||||||
|
SUSP_DIVERSITE = b.comment("Ce nombre de contrôles distincts au palier SETBACK dans la fenêtre = suspect fort ; 0 = coupé.")
|
||||||
|
.defineInRange("diversiteControles", 3, 0, 20);
|
||||||
|
SUSP_DIVERSITE_FENETRE = b.defineInRange("diversiteFenetreMinutes", 10.0, 0.5, 1440.0);
|
||||||
|
SUSP_JOURS = b.comment("Historique des incidents par UUID (gastinelgarde-suspicion/incidents.csv), en jours.")
|
||||||
|
.defineInRange("historiqueJours", 7, 1, 365);
|
||||||
|
b.pop();
|
||||||
|
|
||||||
|
b.comment("0.4.0 : plané en élytres (Elytra Hack), recul absent après un coup subi (Anti Knockback / Anti Push),",
|
||||||
|
"totem remis en main sans délai humain (Auto Totem). Contrôles 'elytres', 'velocite' et 'auto-totem' : OBSERVE par défaut.")
|
||||||
|
.push("nouveauxControles");
|
||||||
|
ELY_MONTEE = b.comment("Ticks de montée sans perte de vitesse en plané avant infraction ; 0 = coupé.")
|
||||||
|
.defineInRange("elytresMonteeTicks", 20, 0, 600);
|
||||||
|
ELY_STATIONNAIRE = b.comment("Ticks de plané presque immobile sans chute avant infraction ; 0 = coupé.")
|
||||||
|
.defineInRange("elytresStationnaireTicks", 20, 0, 600);
|
||||||
|
VEL_FENETRE = b.defineInRange("velociteFenetreTicks", 6, 2, 20);
|
||||||
|
VEL_RAPPORT = b.comment("Recul absent si le déplacement dans le sens du recul est sous cette part du recul vanilla.")
|
||||||
|
.defineInRange("velociteRapportMin", 0.15, 0.0, 1.0);
|
||||||
|
VEL_SERIE = b.comment("Reculs absents (sur les 6 derniers en 2 minutes) avant infraction.")
|
||||||
|
.defineInRange("velociteSerieMin", 3, 1, 6);
|
||||||
|
VEL_FORCE = b.defineInRange("velociteForceMin", 0.15, 0.0, 5.0);
|
||||||
|
VEL_POINTS = b.comment("0.4.1 : points ajoutes par recul absent (en serie). 4 : 6 reculs absents espaces de 3 s depassent le SETBACK (10).")
|
||||||
|
.defineInRange("velocitePoints", 4.0, 0.0, 20.0);
|
||||||
|
TOTEM_SEUIL_SB = b.comment("0.4.2 : seuils propres (0 = seuil global de [sanctions]). Auto-totem : le palier SETBACK reste une alerte.")
|
||||||
|
.defineInRange("autoTotemSeuilSetback", 0.0, 0.0, 1000.0);
|
||||||
|
TOTEM_SEUIL_EXP = b.comment("Auto-totem : expulsion en ENFORCE (9 = trois detections rapprochees a +3).")
|
||||||
|
.defineInRange("autoTotemSeuilExpulsion", 9.0, 0.0, 1000.0);
|
||||||
|
VEL_SEUIL_SB = b.comment("Velocite : retour en arriere (setback) en ENFORCE.")
|
||||||
|
.defineInRange("velociteSeuilSetback", 8.0, 0.0, 1000.0);
|
||||||
|
VEL_SEUIL_EXP = b.comment("Velocite : expulsion en ENFORCE.")
|
||||||
|
.defineInRange("velociteSeuilExpulsion", 16.0, 0.0, 1000.0);
|
||||||
|
TOTEM_DELAI = b.comment("Réaction humaine minimale (ms) entre l'éclatement et le totem remis en main, ping en plus.")
|
||||||
|
.defineInRange("totemDelaiMinMs", 150, 0, 2000);
|
||||||
|
TOTEM_PING = b.defineInRange("totemPingMaxMs", 200, 0, 1000);
|
||||||
|
b.pop();
|
||||||
|
|
||||||
b.push("mouvement");
|
b.push("mouvement");
|
||||||
|
VOL_FLOTTEMENT = b.comment("Vol : ticks consécutifs en l'air sans chute avant infraction (vanilla : 80, 'kicked for floating too long').",
|
||||||
|
"Remplace ce contrôle vanilla si allow-flight=true. 0 = coupé.")
|
||||||
|
.defineInRange("volFlottementTicks", 80, 0, 1200);
|
||||||
EXCES_VITESSE = b.comment("Total d'excès de vitesse horizontale (blocs) sur 20 ticks avant une infraction.",
|
EXCES_VITESSE = b.comment("Total d'excès de vitesse horizontale (blocs) sur 20 ticks avant une infraction.",
|
||||||
"Valeurs de départ généreuses, à resserrer avec les traces réelles.")
|
"Valeurs de départ généreuses, à resserrer avec les traces réelles.")
|
||||||
.defineInRange("excesVitesseBlocs", 1.5, 0.1, 100.0);
|
.defineInRange("excesVitesseBlocs", 1.5, 0.1, 100.0);
|
||||||
@@ -280,6 +341,31 @@ public final class GardeSpec {
|
|||||||
c.seriePingMaxMs = SERIE_PING_MAX.get();
|
c.seriePingMaxMs = SERIE_PING_MAX.get();
|
||||||
c.seriePingMargeMs = SERIE_PING_MARGE.get();
|
c.seriePingMargeMs = SERIE_PING_MARGE.get();
|
||||||
c.timerSoldeMax = TIMER_SOLDE_MAX.get();
|
c.timerSoldeMax = TIMER_SOLDE_MAX.get();
|
||||||
|
c.suspicionActive = SUSP_ACTIVE.get();
|
||||||
|
c.suspicionSeuilSurveiller = SUSP_SURVEILLER.get();
|
||||||
|
c.suspicionSeuilSuspect = Math.max(SUSP_SUSPECT.get(), c.suspicionSeuilSurveiller);
|
||||||
|
c.suspicionSeuilFort = Math.max(SUSP_FORT.get(), c.suspicionSeuilSuspect);
|
||||||
|
c.suspicionDemiVieMinutes = SUSP_DEMI_VIE.get();
|
||||||
|
c.suspicionPlafondFiable = SUSP_PLAFOND_FIABLE.get();
|
||||||
|
c.suspicionPlafondMoyen = SUSP_PLAFOND_MOYEN.get();
|
||||||
|
c.suspicionPlafondFaible = SUSP_PLAFOND_FAIBLE.get();
|
||||||
|
c.suspicionDiversiteControles = SUSP_DIVERSITE.get();
|
||||||
|
c.suspicionDiversiteFenetreMinutes = SUSP_DIVERSITE_FENETRE.get();
|
||||||
|
c.suspicionHistoriqueJours = SUSP_JOURS.get();
|
||||||
|
c.volFlottementTicks = VOL_FLOTTEMENT.get();
|
||||||
|
c.elytresMonteeTicks = ELY_MONTEE.get();
|
||||||
|
c.elytresStationnaireTicks = ELY_STATIONNAIRE.get();
|
||||||
|
c.velociteFenetreTicks = VEL_FENETRE.get();
|
||||||
|
c.velociteRapportMin = VEL_RAPPORT.get();
|
||||||
|
c.velociteSerieMin = VEL_SERIE.get();
|
||||||
|
c.velociteForceMin = VEL_FORCE.get();
|
||||||
|
c.velocitePoints = VEL_POINTS.get();
|
||||||
|
c.autoTotemSeuilSetback = TOTEM_SEUIL_SB.get();
|
||||||
|
c.autoTotemSeuilExpulsion = TOTEM_SEUIL_EXP.get();
|
||||||
|
c.velociteSeuilSetback = VEL_SEUIL_SB.get();
|
||||||
|
c.velociteSeuilExpulsion = VEL_SEUIL_EXP.get();
|
||||||
|
c.totemDelaiMinMs = TOTEM_DELAI.get();
|
||||||
|
c.totemPingMaxMs = TOTEM_PING.get();
|
||||||
c.volFenetreGlissante = VOL_FENETRE_GLISSANTE.get();
|
c.volFenetreGlissante = VOL_FENETRE_GLISSANTE.get();
|
||||||
c.vitesseMoyenne = VITESSE_MOYENNE.get();
|
c.vitesseMoyenne = VITESSE_MOYENNE.get();
|
||||||
c.elytresExemptionStricte = ELYTRES_STRICTE.get();
|
c.elytresExemptionStricte = ELYTRES_STRICTE.get();
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.gastinelgarde.core;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contrôle « auto-totem » (0.4.0). Le cheat remet un totem en main dès l'éclatement, sans délai de réaction. Le
|
||||||
|
* serveur voit l'éclatement (LivingUseTotemEvent) puis le contenu des mains à chaque paquet de mouvement : le délai
|
||||||
|
* entre les deux ne peut pas être inférieur à l'aller-retour réseau (le client apprend l'éclatement après ping/2, sa
|
||||||
|
* demande arrive après ping/2 de plus) plus la réaction humaine (~150 ms, arrondi au tick de 50 ms). Le ping est
|
||||||
|
* falsifiable (F07) : il n'entre que borné à {@link GardeConfig#totemPingMaxMs}, donc un joueur qui gonfle son ping
|
||||||
|
* ne gagne qu'une marge limitée. Un totem de réserve déjà en main à l'éclatement annule la mesure.
|
||||||
|
*/
|
||||||
|
public final class AutoTotem {
|
||||||
|
|
||||||
|
/** Mesure abandonnée si aucun totem n'est remis dans ce délai. */
|
||||||
|
public static final long EXPIRATION_MS = 10_000;
|
||||||
|
|
||||||
|
private boolean actif;
|
||||||
|
private long eclatMs;
|
||||||
|
|
||||||
|
/** @param reserveEnMain un autre totem était déjà dans l'autre main : rien à mesurer */
|
||||||
|
public void eclatement(long nowMs, boolean reserveEnMain) {
|
||||||
|
actif = !reserveEnMain;
|
||||||
|
eclatMs = nowMs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contenu des mains à un paquet de mouvement.
|
||||||
|
*
|
||||||
|
* @return points d'infraction (0 si rien)
|
||||||
|
*/
|
||||||
|
public double mains(long nowMs, boolean totemEnMain, int pingMs, GardeConfig cfg) {
|
||||||
|
if (!actif) return 0;
|
||||||
|
if (nowMs - eclatMs > EXPIRATION_MS) {
|
||||||
|
actif = false;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (!totemEnMain || nowMs <= eclatMs) return 0;
|
||||||
|
actif = false;
|
||||||
|
long delai = nowMs - eclatMs;
|
||||||
|
long minimum = cfg.totemDelaiMinMs + Math.min(Math.max(0, pingMs), cfg.totemPingMaxMs);
|
||||||
|
return delai < minimum ? 3.0 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void vider() {
|
||||||
|
actif = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,7 +17,13 @@ public enum Controle {
|
|||||||
VITESSE("vitesse"),
|
VITESSE("vitesse"),
|
||||||
VOL("vol"),
|
VOL("vol"),
|
||||||
VEHICULE_VITESSE("vehicule-vitesse"),
|
VEHICULE_VITESSE("vehicule-vitesse"),
|
||||||
VEHICULE_VOL("vehicule-vol");
|
VEHICULE_VOL("vehicule-vol"),
|
||||||
|
/** 0.4.0 : plané en élytres (Elytra Hack) : montée sans perte de vitesse, plané immobile. */
|
||||||
|
ELYTRES("elytres"),
|
||||||
|
/** 0.4.0 : recul absent après un coup subi (Anti Knockback, Anti Push). */
|
||||||
|
VELOCITE("velocite"),
|
||||||
|
/** 0.4.0 : totem remis en main sans délai humain après l'éclatement (Auto Totem). */
|
||||||
|
AUTO_TOTEM("auto-totem");
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
|
|
||||||
@@ -39,6 +45,15 @@ public enum Controle {
|
|||||||
|| this == COUPS_HORS_BOITE;
|
|| this == COUPS_HORS_BOITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Fiabilité du contrôle pour le score de suspicion : 0 = fiable, 1 = moyen, 2 = sujet aux faux positifs. */
|
||||||
|
public int fiabilite() {
|
||||||
|
return switch (this) {
|
||||||
|
case VOL, VITESSE, NO_FALL, PORTEE, HITBOX, REGULARITE, AUTO_TOTEM -> 0; // AUTO_TOTEM : 0.4.1
|
||||||
|
case COUPS_HORS_BOITE, KILLAURA_ANGLE, KILLAURA_CIBLES, CADENCE -> 1;
|
||||||
|
case TIMER, ROTATION, ATTAQUE_IMPOSSIBLE, VEHICULE_VITESSE, VEHICULE_VOL, ELYTRES, VELOCITE -> 2;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public static Controle parse(String texte) {
|
public static Controle parse(String texte) {
|
||||||
if (texte == null) return null;
|
if (texte == null) return null;
|
||||||
for (Controle c : values()) {
|
for (Controle c : values()) {
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ public record EtatJoueur(
|
|||||||
int ticksDepuisRecul,
|
int ticksDepuisRecul,
|
||||||
int ticksDepuisGel,
|
int ticksDepuisGel,
|
||||||
double tps,
|
double tps,
|
||||||
int pingMs) {
|
int pingMs,
|
||||||
|
boolean propulsionRecente) {
|
||||||
|
|
||||||
public static final int JAMAIS = Integer.MAX_VALUE;
|
public static final int JAMAIS = Integer.MAX_VALUE;
|
||||||
|
|
||||||
@@ -39,6 +40,7 @@ public record EtatJoueur(
|
|||||||
private int ticksDepuisTeleport = JAMAIS, ticksDepuisRecul = JAMAIS, ticksDepuisGel = JAMAIS;
|
private int ticksDepuisTeleport = JAMAIS, ticksDepuisRecul = JAMAIS, ticksDepuisGel = JAMAIS;
|
||||||
private double tps = 20.0;
|
private double tps = 20.0;
|
||||||
private int pingMs = 30;
|
private int pingMs = 30;
|
||||||
|
private boolean propulsionRecente;
|
||||||
|
|
||||||
public Builder creatif(boolean v) { creatif = v; return this; }
|
public Builder creatif(boolean v) { creatif = v; return this; }
|
||||||
public Builder spectateur(boolean v) { spectateur = v; return this; }
|
public Builder spectateur(boolean v) { spectateur = v; return this; }
|
||||||
@@ -57,11 +59,13 @@ public record EtatJoueur(
|
|||||||
public Builder ticksDepuisGel(int v) { ticksDepuisGel = v; return this; }
|
public Builder ticksDepuisGel(int v) { ticksDepuisGel = v; return this; }
|
||||||
public Builder tps(double v) { tps = v; return this; }
|
public Builder tps(double v) { tps = v; return this; }
|
||||||
public Builder pingMs(int v) { pingMs = v; return this; }
|
public Builder pingMs(int v) { pingMs = v; return this; }
|
||||||
|
/** 0.4.0 : fusée de feu d'artifice (ou autre poussée connue du serveur) récente : plané non contrôlé. */
|
||||||
|
public Builder propulsionRecente(boolean v) { propulsionRecente = v; return this; }
|
||||||
|
|
||||||
public EtatJoueur build() {
|
public EtatJoueur build() {
|
||||||
return new EtatJoueur(creatif, spectateur, peutVoler, riptide, elytres, levitation, chuteLente,
|
return new EtatJoueur(creatif, spectateur, peutVoler, riptide, elytres, levitation, chuteLente,
|
||||||
enVehicule, pocheContraption, utiliseObjet, elytresDeploiementSuspect, ticksDepuisTeleport, ticksDepuisRecul,
|
enVehicule, pocheContraption, utiliseObjet, elytresDeploiementSuspect, ticksDepuisTeleport, ticksDepuisRecul,
|
||||||
ticksDepuisGel, tps, pingMs);
|
ticksDepuisGel, tps, pingMs, propulsionRecente);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,6 +26,51 @@ public final class GardeConfig {
|
|||||||
/** C1 (16/10) : ticks de grâce du contrôle vol après la fin du plané en élytres (fin à l'atterrissage). */
|
/** C1 (16/10) : ticks de grâce du contrôle vol après la fin du plané en élytres (fin à l'atterrissage). */
|
||||||
public int graceFinElytresTicks = 50;
|
public int graceFinElytresTicks = 50;
|
||||||
|
|
||||||
|
// --- Score de suspicion (0.4.0, section [suspicion]) : information pour les humains, jamais de sanction ---
|
||||||
|
public boolean suspicionActive = true;
|
||||||
|
public double suspicionSeuilSurveiller = 25;
|
||||||
|
public double suspicionSeuilSuspect = 50;
|
||||||
|
public double suspicionSeuilFort = 75;
|
||||||
|
/** Demi-vie du score, en minutes de jeu (le suivi du joueur est libéré à la déconnexion). */
|
||||||
|
public double suspicionDemiVieMinutes = 10;
|
||||||
|
/** Plafonds de contribution par fiabilité du contrôle (fiable / moyen / sujet aux faux positifs). */
|
||||||
|
public double suspicionPlafondFiable = 50;
|
||||||
|
public double suspicionPlafondMoyen = 30;
|
||||||
|
public double suspicionPlafondFaible = 15;
|
||||||
|
/** Diversité : ce nombre de contrôles distincts au palier SETBACK ou plus dans la fenêtre = suspect fort. */
|
||||||
|
public int suspicionDiversiteControles = 3;
|
||||||
|
public double suspicionDiversiteFenetreMinutes = 10;
|
||||||
|
public int suspicionHistoriqueJours = 7;
|
||||||
|
|
||||||
|
// --- Vol : flottement (0.4.0), équivalent du « kicked for floating too long » vanilla (80 ticks) ---
|
||||||
|
/** Ticks consécutifs en l'air sans chute (dy par tick >= -0,03125, comme vanilla) avant infraction ; 0 = coupé. */
|
||||||
|
public int volFlottementTicks = 80;
|
||||||
|
|
||||||
|
// --- 0.4.0 : plané (elytres), vélocité (recul), auto-totem. OBSERVE par défaut, valeurs à valider en jeu ---
|
||||||
|
/** Ticks de montée sans perte de vitesse en plané avant infraction ; 0 = coupé. */
|
||||||
|
public int elytresMonteeTicks = 20;
|
||||||
|
/** Ticks de plané presque immobile et sans chute avant infraction ; 0 = coupé. */
|
||||||
|
public int elytresStationnaireTicks = 20;
|
||||||
|
/** Ticks sur lesquels le recul est mesuré après un coup subi. */
|
||||||
|
public int velociteFenetreTicks = 6;
|
||||||
|
/** Recul absent si le déplacement dans le sens du recul est sous cette part du recul vanilla. */
|
||||||
|
public double velociteRapportMin = 0.15;
|
||||||
|
/** Reculs absents (sur les 6 derniers en 2 min) avant infraction. */
|
||||||
|
public int velociteSerieMin = 3;
|
||||||
|
/** Force de recul effective (après résistance) en dessous de laquelle on ne mesure pas. */
|
||||||
|
public double velociteForceMin = 0.15;
|
||||||
|
/** 0.4.1 : points par recul absent compte (en serie). 2 en dur en 0.4.0 : la decroissance (0,5/s) plafonnait le VL vers 5. */
|
||||||
|
public double velocitePoints = 4.0;
|
||||||
|
/** 0.4.2 : seuils propres a un controle ; valeur <= 0 = seuil global de [sanctions]. */
|
||||||
|
public double autoTotemSeuilSetback = 0;
|
||||||
|
public double autoTotemSeuilExpulsion = 9;
|
||||||
|
public double velociteSeuilSetback = 8;
|
||||||
|
public double velociteSeuilExpulsion = 16;
|
||||||
|
/** Réaction humaine minimale (ms) entre l'éclatement d'un totem et un totem remis en main, hors ping. */
|
||||||
|
public int totemDelaiMinMs = 150;
|
||||||
|
/** Ping (ms) au plus ajouté à ce délai (le ping est falsifiable). */
|
||||||
|
public int totemPingMaxMs = 200;
|
||||||
|
|
||||||
// --- Killaura ---
|
// --- Killaura ---
|
||||||
/** Angle maximal entre le regard et la silhouette de la cible, en degrés. */
|
/** Angle maximal entre le regard et la silhouette de la cible, en degrés. */
|
||||||
public double angleMaxDegres = 60.0;
|
public double angleMaxDegres = 60.0;
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package com.gastinelgarde.core;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardOpenOption;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Incidents de suspicion par UUID sur N jours (par défaut 7). Un incident = un franchissement vers « suspect » ou
|
||||||
|
* « suspect fort ». Persistance : un fichier texte, une ligne par incident, en ajout seulement (une coupure ne
|
||||||
|
* peut pas le corrompre au-delà d'une ligne, aucune dépendance, lisible à la main). Les lignes trop vieilles ou
|
||||||
|
* illisibles sont ignorées au chargement, et le fichier est réécrit compact si quelque chose a été écarté.
|
||||||
|
* Format : {@code epochMs;uuid;niveau;score;controles}.
|
||||||
|
*/
|
||||||
|
public final class HistoriqueSuspicion {
|
||||||
|
|
||||||
|
public record Incident(long epochMs, Suspicion.Niveau niveau, int score, String controles) { }
|
||||||
|
|
||||||
|
private final Map<UUID, List<Incident>> incidents = new HashMap<>();
|
||||||
|
private Path fichier;
|
||||||
|
|
||||||
|
/** Charge le fichier (s'il existe), ignore ce qui a plus de {@code jours} jours, et mémorise le chemin. */
|
||||||
|
public synchronized void ouvrir(Path chemin, long nowEpochMs, int jours) throws IOException {
|
||||||
|
this.fichier = chemin;
|
||||||
|
incidents.clear();
|
||||||
|
if (!Files.exists(chemin)) return;
|
||||||
|
long limite = nowEpochMs - jours * 86_400_000L;
|
||||||
|
boolean ecarte = false;
|
||||||
|
for (String ligne : Files.readAllLines(chemin, StandardCharsets.UTF_8)) {
|
||||||
|
if (ligne.isBlank()) continue;
|
||||||
|
String[] t = ligne.split(";", 5);
|
||||||
|
try {
|
||||||
|
if (t.length < 4) throw new IllegalArgumentException();
|
||||||
|
long ts = Long.parseLong(t[0]);
|
||||||
|
if (ts < limite) {
|
||||||
|
ecarte = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
incidents.computeIfAbsent(UUID.fromString(t[1]), k -> new ArrayList<>()).add(new Incident(ts,
|
||||||
|
Suspicion.Niveau.valueOf(t[2]), Integer.parseInt(t[3]), t.length > 4 ? t[4] : ""));
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
ecarte = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ecarte) reecrire();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void enregistrer(UUID joueur, long epochMs, Suspicion.Niveau niveau, int score, String controles) {
|
||||||
|
String ctl = controles == null ? "" : controles.replace(';', ',').replace('\n', ' ');
|
||||||
|
List<Incident> l = incidents.computeIfAbsent(joueur, k -> new ArrayList<>());
|
||||||
|
Incident i = new Incident(epochMs, niveau, score, ctl);
|
||||||
|
l.add(i);
|
||||||
|
if (fichier == null) return;
|
||||||
|
try {
|
||||||
|
if (fichier.getParent() != null) Files.createDirectories(fichier.getParent());
|
||||||
|
Files.writeString(fichier, ligne(joueur, i), StandardCharsets.UTF_8,
|
||||||
|
StandardOpenOption.CREATE, StandardOpenOption.APPEND);
|
||||||
|
} catch (IOException e) {
|
||||||
|
// la mémoire reste juste ; le fichier sera réécrit compact au prochain chargement
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Nombre d'incidents des {@code jours} derniers jours. */
|
||||||
|
public synchronized int incidents(UUID joueur, long nowEpochMs, int jours) {
|
||||||
|
long limite = nowEpochMs - jours * 86_400_000L;
|
||||||
|
int n = 0;
|
||||||
|
for (Incident i : incidents.getOrDefault(joueur, List.of())) if (i.epochMs() >= limite) n++;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String ligne(UUID id, Incident i) {
|
||||||
|
return i.epochMs() + ";" + id + ";" + i.niveau() + ";" + i.score() + ";" + i.controles() + System.lineSeparator();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reecrire() throws IOException {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
incidents.forEach((id, l) -> l.forEach(i -> sb.append(ligne(id, i))));
|
||||||
|
Files.writeString(fichier, sb.toString(), StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,45 @@ public final class Moteur {
|
|||||||
/** C4 : joueurs déjà expulsés (jusqu'à leur reconnexion). */
|
/** C4 : joueurs déjà expulsés (jusqu'à leur reconnexion). */
|
||||||
private final java.util.Set<UUID> expulses = new java.util.HashSet<>();
|
private final java.util.Set<UUID> expulses = new java.util.HashSet<>();
|
||||||
|
|
||||||
|
private java.util.function.LongSupplier horloge = System::currentTimeMillis;
|
||||||
|
private final HistoriqueSuspicion historique = new HistoriqueSuspicion();
|
||||||
|
|
||||||
|
/** Horloge du score de suspicion (ms) ; remplaçable dans les tests. */
|
||||||
|
public void horloge(java.util.function.LongSupplier h) {
|
||||||
|
this.horloge = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HistoriqueSuspicion historique() {
|
||||||
|
return historique;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Alerte de suspicion : franchissement vers le haut d'un palier. */
|
||||||
|
public record AlerteSuspicion(Suspicion.Niveau niveau, int score, int incidents, String controles) { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Franchissement de palier en attente pour ce joueur (null sinon). À partir de « suspect », l'incident est ajouté à
|
||||||
|
* l'historique. Aucune sanction ici : c'est une information pour les humains.
|
||||||
|
*/
|
||||||
|
public AlerteSuspicion alerteSuspicion(UUID joueur, long epochMs) {
|
||||||
|
Suivi s = suivis.get(joueur);
|
||||||
|
if (s == null) return null;
|
||||||
|
Suspicion.Niveau n = s.suspicion.prendreTransition();
|
||||||
|
if (n == null) return null;
|
||||||
|
long now = horloge.getAsLong();
|
||||||
|
int score = (int) Math.round(s.suspicion.score(now));
|
||||||
|
String ctl = s.suspicion.resume(now);
|
||||||
|
if (n.ordinal() >= Suspicion.Niveau.SUSPECT.ordinal()) {
|
||||||
|
historique.enregistrer(joueur, epochMs, n, score, ctl);
|
||||||
|
}
|
||||||
|
return new AlerteSuspicion(n, score, historique.incidents(joueur, epochMs, cfg.suspicionHistoriqueJours), ctl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Score courant d'un joueur suivi (0 si inconnu). */
|
||||||
|
public double scoreSuspicion(UUID joueur) {
|
||||||
|
Suivi s = suivis.get(joueur);
|
||||||
|
return s == null ? 0 : s.suspicion.score(horloge.getAsLong());
|
||||||
|
}
|
||||||
|
|
||||||
public Moteur(GardeConfig cfg) {
|
public Moteur(GardeConfig cfg) {
|
||||||
this.cfg = cfg;
|
this.cfg = cfg;
|
||||||
}
|
}
|
||||||
@@ -33,7 +72,7 @@ public final class Moteur {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Suivi suivi(UUID joueur) {
|
public Suivi suivi(UUID joueur) {
|
||||||
return suivis.computeIfAbsent(joueur, k -> new Suivi(cfg.vlDecroissanceParSeconde));
|
return suivis.computeIfAbsent(joueur, k -> new Suivi(cfg.vlDecroissanceParSeconde, cfg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void retirer(UUID joueur) {
|
public void retirer(UUID joueur) {
|
||||||
@@ -341,12 +380,22 @@ public final class Moteur {
|
|||||||
// 15/10 : l'élan réel de la période exemptée est gardé (élytres arrêtées en plein vol, recul…).
|
// 15/10 : l'élan réel de la période exemptée est gardé (élytres arrêtées en plein vol, recul…).
|
||||||
s.vitesse.exempter(m, ex.facteur(), sortieDEtat(ex.raisons()));
|
s.vitesse.exempter(m, ex.facteur(), sortieDEtat(ex.raisons()));
|
||||||
s.vol.vider();
|
s.vol.vider();
|
||||||
|
// 0.4.0 : plané seul exempté -> contrôle « elytres » (Elytra Hack). Toute autre exemption l'écarte.
|
||||||
|
List<Verdict> plane = new ArrayList<>(1);
|
||||||
|
if (ex.raisons().size() == 1 && ex.raisons().get(0).equals("elytres")
|
||||||
|
&& cfg.mode(Controle.ELYTRES) != Mode.OFF) {
|
||||||
|
ajouter(plane, s, Controle.ELYTRES, s.plane.enregistrer(m, etat.propulsionRecente(), cfg), nowMs, ex,
|
||||||
|
String.format(Locale.ROOT, "plane dxz=%.3f dy=%.3f ticks=%d", m.dxz(), m.dy(), m.ticks()));
|
||||||
|
} else {
|
||||||
|
s.plane.vider();
|
||||||
|
}
|
||||||
// C1 (16/10, incident Rednixxu) : le drapeau élytres tombe côté serveur alors que le client plane encore.
|
// C1 (16/10, incident Rednixxu) : le drapeau élytres tombe côté serveur alors que le client plane encore.
|
||||||
if (ex.raisons().contains("elytres")) {
|
if (ex.raisons().contains("elytres")) {
|
||||||
s.graceElytresJusquaMs = nowMs + cfg.graceFinElytresTicks * 50L;
|
s.graceElytresJusquaMs = nowMs + cfg.graceFinElytresTicks * 50L;
|
||||||
}
|
}
|
||||||
return List.of();
|
return plane;
|
||||||
}
|
}
|
||||||
|
s.plane.vider(); // plus en plané (atterrissage, fin des élytres) : ni référence de vitesse ni compteur gardés
|
||||||
List<Verdict> verdicts = new ArrayList<>(3);
|
List<Verdict> verdicts = new ArrayList<>(3);
|
||||||
if (noFall) {
|
if (noFall) {
|
||||||
ajouter(verdicts, s, Controle.NO_FALL, NoFall.points(m), nowMs, ex,
|
ajouter(verdicts, s, Controle.NO_FALL, NoFall.points(m), nowMs, ex,
|
||||||
@@ -369,6 +418,7 @@ public final class Moteur {
|
|||||||
s.vol.vider(); // le paquet qui suit la grâce sert de référence
|
s.vol.vider(); // le paquet qui suit la grâce sert de référence
|
||||||
} else if (vol) {
|
} else if (vol) {
|
||||||
s.vol.fenetreGlissante = cfg.volFenetreGlissante; // C10, désactivé par défaut
|
s.vol.fenetreGlissante = cfg.volFenetreGlissante; // C10, désactivé par défaut
|
||||||
|
s.vol.flottementMax = cfg.volFlottementTicks; // 0.4.0 : flottement prolongé (80 ticks comme vanilla)
|
||||||
double pts = s.vol.enregistrer(m, false);
|
double pts = s.vol.enregistrer(m, false);
|
||||||
ajouter(verdicts, s, Controle.VOL, pts, nowMs, ex, String.format(Locale.ROOT, "dy=%.3f en l'air", m.dy()));
|
ajouter(verdicts, s, Controle.VOL, pts, nowMs, ex, String.format(Locale.ROOT, "dy=%.3f en l'air", m.dy()));
|
||||||
}
|
}
|
||||||
@@ -436,6 +486,65 @@ public final class Moteur {
|
|||||||
return NoFall.auSolEffectif(auSolClient, auSolServeur, ex.exempt(), cfg.mode(Controle.NO_FALL));
|
return NoFall.auSolEffectif(auSolClient, auSolServeur, ex.exempt(), cfg.mode(Controle.NO_FALL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- 0.4.0 : vélocité (recul) et auto-totem ---
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Le serveur applique un recul au joueur (coup, explosion, charge de vent).
|
||||||
|
*
|
||||||
|
* @param dirX,dirZ direction du déplacement attendu ; {@code force} effective, résistance déduite
|
||||||
|
*/
|
||||||
|
public void reculApplique(UUID joueur, long nowMs, double dirX, double dirZ, double force, boolean libre) {
|
||||||
|
if (cfg.mode(Controle.VELOCITE) == Mode.OFF || expulses.contains(joueur)) return;
|
||||||
|
// Joueur coincé (mur, trou, plafond) : le recul n'a pas pu avoir lieu, rien à mesurer.
|
||||||
|
if (!libre) {
|
||||||
|
suivi(joueur).velocite.abandonner();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
suivi(joueur).velocite.recul(nowMs, dirX, dirZ, force, cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Nouvelle fusée tirée en plané par ce joueur : le gain de vitesse est mesuré depuis zéro. */
|
||||||
|
public void nouvelleFusee(UUID joueur) {
|
||||||
|
suivi(joueur).plane.nouvelleFusee();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Déplacement horizontal de ce paquet accepté (dx, dz signés), pour mesurer le recul en cours. */
|
||||||
|
public List<Verdict> mesureRecul(UUID joueur, long nowMs, EtatJoueur etat, double dx, double dz, boolean milieuSpecial,
|
||||||
|
java.util.function.BiPredicate<Double, Double> bloqueDansLeSens) {
|
||||||
|
if (cfg.mode(Controle.VELOCITE) == Mode.OFF || expulses.contains(joueur)) return List.of();
|
||||||
|
Suivi s = suivis.get(joueur);
|
||||||
|
if (s == null) return List.of();
|
||||||
|
boolean neutre = milieuSpecial || etat.ticksDepuisGel() <= cfg.graceGelTicks
|
||||||
|
|| etat.tps() < cfg.tpsLag || etat.creatif() || etat.spectateur() || etat.peutVoler() || etat.elytres()
|
||||||
|
|| etat.enVehicule() || etat.riptide() || etat.pocheContraption()
|
||||||
|
|| etat.ticksDepuisTeleport() <= cfg.graceTeleportTicks;
|
||||||
|
// Collision testée seulement dans le sens du recul (le prédicat n'est évalué que pendant une mesure) : se coller
|
||||||
|
// à un mur ailleurs n'annule rien.
|
||||||
|
boolean bloque = s.velocite.actif() && bloqueDansLeSens.test(s.velocite.dirX(), s.velocite.dirZ());
|
||||||
|
double pts = s.velocite.mouvement(nowMs, dx, dz, neutre, bloque, cfg);
|
||||||
|
List<Verdict> v = new ArrayList<>(1);
|
||||||
|
ajouter(v, s, Controle.VELOCITE, pts, nowMs, Exemptions.evaluer(etat, cfg, Exemptions.Famille.COMBAT),
|
||||||
|
"recul absent apres un coup subi (serie)");
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Un totem vient d'éclater ; {@code reserveEnMain} : un autre totem est déjà dans l'autre main. */
|
||||||
|
public void totemEclate(UUID joueur, long nowMs, boolean reserveEnMain) {
|
||||||
|
if (cfg.mode(Controle.AUTO_TOTEM) == Mode.OFF || expulses.contains(joueur)) return;
|
||||||
|
suivi(joueur).totem.eclatement(nowMs, reserveEnMain);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Contenu des mains (au moins un totem ?) à un paquet de mouvement après un éclatement. */
|
||||||
|
public List<Verdict> totemEnMain(UUID joueur, long nowMs, EtatJoueur etat, boolean totemEnMain) {
|
||||||
|
if (cfg.mode(Controle.AUTO_TOTEM) == Mode.OFF || expulses.contains(joueur)) return List.of();
|
||||||
|
Suivi s = suivis.get(joueur);
|
||||||
|
if (s == null) return List.of();
|
||||||
|
List<Verdict> v = new ArrayList<>(1);
|
||||||
|
ajouter(v, s, Controle.AUTO_TOTEM, s.totem.mains(nowMs, totemEnMain, etat.pingMs(), cfg), nowMs,
|
||||||
|
Exemptions.evaluer(etat, cfg, Exemptions.Famille.COMBAT), "totem remis en main trop vite apres l'eclatement");
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
// --- Setback, expulsion, position de retour (16/10, incident VOL) ----------------------------------------
|
// --- Setback, expulsion, position de retour (16/10, incident VOL) ----------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -486,13 +595,19 @@ public final class Moteur {
|
|||||||
if (points <= 0) return;
|
if (points <= 0) return;
|
||||||
Mode mode = cfg.mode(c);
|
Mode mode = cfg.mode(c);
|
||||||
double vl = s.vl.ajouter(c, points, nowMs);
|
double vl = s.vl.ajouter(c, points, nowMs);
|
||||||
Sanction palier = Paliers.palier(vl, cfg);
|
Sanction palier = Paliers.palier(vl, cfg, c); // 0.4.2 : seuils propres a auto-totem et velocite
|
||||||
// C5 (16/10) : après un setback, le VL repart de zéro ; l'expulsion vient après plusieurs setbacks récents.
|
// C5 (16/10) : après un setback, le VL repart de zéro ; l'expulsion vient après plusieurs setbacks récents.
|
||||||
if (palier == Sanction.SETBACK && cfg.setbacksAvantExpulsion > 0
|
if (palier == Sanction.SETBACK && cfg.setbacksAvantExpulsion > 0
|
||||||
&& s.setbacksRecents(nowMs, cfg.fenetreSetbacksMs) >= cfg.setbacksAvantExpulsion) {
|
&& s.setbacksRecents(nowMs, cfg.fenetreSetbacksMs) >= cfg.setbacksAvantExpulsion) {
|
||||||
palier = Sanction.min(Sanction.EXPULSION, cfg.sanctionMax);
|
palier = Sanction.min(Sanction.EXPULSION, cfg.sanctionMax);
|
||||||
}
|
}
|
||||||
Sanction applicable = Paliers.applicable(palier, mode);
|
Sanction applicable = Paliers.applicable(palier, mode);
|
||||||
|
// 0.4.0 : vélocité et auto-totem sont bridés dans le code (un tiers peut provoquer de faux positifs) : jamais de
|
||||||
|
// setback ni d'expulsion, même si la configuration les passe en ENFORCE. Ils nourrissent le score de suspicion.
|
||||||
|
// 0.4.2 (decision de Theo) : vraies sanctions en ENFORCE. Auto-totem n'a pas de retour en arriere qui ait un
|
||||||
|
// sens : son palier SETBACK reste une ALERTE, l'expulsion s'applique. Velocite : SETBACK = retour en arriere.
|
||||||
|
if (c == Controle.AUTO_TOTEM && applicable == Sanction.SETBACK) applicable = Sanction.ALERTE;
|
||||||
|
s.suspicion.noter(c, vl, palier.ordinal() >= Sanction.SETBACK.ordinal(), horloge.getAsLong());
|
||||||
boolean notifier = applicable.ordinal() >= Sanction.ALERTE.ordinal()
|
boolean notifier = applicable.ordinal() >= Sanction.ALERTE.ordinal()
|
||||||
&& s.autoriserAlerte(c, nowMs, DELAI_ALERTE_MS);
|
&& s.autoriserAlerte(c, nowMs, DELAI_ALERTE_MS);
|
||||||
sortie.add(new Verdict(c, mode, points, vl, palier, applicable, notifier, details, ex.raisons()));
|
sortie.add(new Verdict(c, mode, points, vl, palier, applicable, notifier, details, ex.raisons()));
|
||||||
|
|||||||
@@ -7,11 +7,32 @@ public final class Paliers {
|
|||||||
|
|
||||||
/** Sanction que mériterait ce nombre de points, plafonnée par {@code sanctionMax}. */
|
/** Sanction que mériterait ce nombre de points, plafonnée par {@code sanctionMax}. */
|
||||||
public static Sanction palier(double vl, GardeConfig cfg) {
|
public static Sanction palier(double vl, GardeConfig cfg) {
|
||||||
|
return palier(vl, cfg.seuilAlerte, cfg.seuilSetback, cfg.seuilExpulsion, cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 0.4.2 : palier avec les seuils propres au contrôle (auto-totem, vélocité) quand ils sont définis (> 0). */
|
||||||
|
public static Sanction palier(double vl, GardeConfig cfg, Controle c) {
|
||||||
|
double setback = cfg.seuilSetback;
|
||||||
|
double expulsion = cfg.seuilExpulsion;
|
||||||
|
if (c == Controle.AUTO_TOTEM) {
|
||||||
|
if (cfg.autoTotemSeuilSetback > 0) setback = cfg.autoTotemSeuilSetback;
|
||||||
|
if (cfg.autoTotemSeuilExpulsion > 0) expulsion = cfg.autoTotemSeuilExpulsion;
|
||||||
|
} else if (c == Controle.VELOCITE) {
|
||||||
|
if (cfg.velociteSeuilSetback > 0) setback = cfg.velociteSeuilSetback;
|
||||||
|
if (cfg.velociteSeuilExpulsion > 0) expulsion = cfg.velociteSeuilExpulsion;
|
||||||
|
}
|
||||||
|
setback = Math.min(setback, expulsion);
|
||||||
|
double alerte = Math.min(cfg.seuilAlerte, setback);
|
||||||
|
return palier(vl, alerte, setback, expulsion, cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Sanction palier(double vl, double seuilAlerte, double seuilSetback, double seuilExpulsion,
|
||||||
|
GardeConfig cfg) {
|
||||||
Sanction s;
|
Sanction s;
|
||||||
if (vl <= 0) s = Sanction.AUCUNE;
|
if (vl <= 0) s = Sanction.AUCUNE;
|
||||||
else if (vl < cfg.seuilAlerte) s = Sanction.JOURNAL;
|
else if (vl < seuilAlerte) s = Sanction.JOURNAL;
|
||||||
else if (vl < cfg.seuilSetback) s = Sanction.ALERTE;
|
else if (vl < seuilSetback) s = Sanction.ALERTE;
|
||||||
else if (vl < cfg.seuilExpulsion) s = Sanction.SETBACK;
|
else if (vl < seuilExpulsion) s = Sanction.SETBACK;
|
||||||
else s = Sanction.EXPULSION;
|
else s = Sanction.EXPULSION;
|
||||||
return Sanction.min(s, cfg.sanctionMax);
|
return Sanction.min(s, cfg.sanctionMax);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,175 @@
|
|||||||
|
package com.gastinelgarde.core;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contrôle « elytres » (0.4.0) : le plané est exempté de vitesse, de vol et de no-fall (Exemptions, famille
|
||||||
|
* mouvement). Le « Elytra Hack » de CheatUtils (méthode VanillaFly) donne au plané l'accélération verticale et
|
||||||
|
* horizontale du vol créatif : on monte à vitesse constante ou on reste sur place. Le vanilla ne le permet pas :
|
||||||
|
* <ul>
|
||||||
|
* <li>monter coûte de la vitesse horizontale (l'énergie vient de la piqué) : une montée de plus de
|
||||||
|
* {@link GardeConfig#elytresMonteeTicks} ticks sans perte de vitesse est impossible sans fusée ;</li>
|
||||||
|
* <li>rester presque immobile sans chute ({@link GardeConfig#elytresStationnaireTicks} ticks) est impossible :
|
||||||
|
* à faible vitesse la portance est nulle et le joueur tombe.</li>
|
||||||
|
* </ul>
|
||||||
|
* Aucune des deux règles ne s'applique après une fusée (propulsion récente), dans un milieu spécial (courant d'air
|
||||||
|
* Create, colonne à bulles, eau…), ni quand une autre exemption est active (le moteur n'appelle ce contrôle que si
|
||||||
|
* « elytres » est la seule raison d'exemption). Les valeurs sont à confirmer en jeu : OBSERVE par défaut.
|
||||||
|
*
|
||||||
|
* <p>Pourquoi l'option C7 ({@code elytresExemptionStricte}) ne suffit pas : elle retire seulement l'exemption quand
|
||||||
|
* le plané démarre sans ticks en l'air côté serveur (onGround falsifié). Un tricheur qui saute puis déploie ses
|
||||||
|
* élytres normalement reste exempté de tout, et C7 ne regarde jamais ce que le plané fait ensuite.
|
||||||
|
*/
|
||||||
|
public final class PlaneElytres {
|
||||||
|
|
||||||
|
/** Montée franche (blocs par tick) ; en dessous, c'est du plané à plat. */
|
||||||
|
public static final double MONTEE_MIN = 0.05;
|
||||||
|
/** Une montée qui garde au moins cette part de la vitesse horizontale du début est suspecte. */
|
||||||
|
public static final double VITESSE_GARDEE = 0.9;
|
||||||
|
/** Vitesse horizontale (blocs par tick) en dessous de laquelle le plané ne porte plus. */
|
||||||
|
public static final double VITESSE_STATIONNAIRE = 0.15;
|
||||||
|
/** Chute (blocs par tick) en dessous de laquelle on ne tombe pas vraiment. */
|
||||||
|
public static final double CHUTE_MIN = -0.04;
|
||||||
|
/** Paquets au-delà de ce nombre de ticks : pas de mesure fiable (retard réseau). */
|
||||||
|
public static final int TICKS_MAX = 3;
|
||||||
|
|
||||||
|
/** Ticks de grâce après lesquels on exige que la fusée ait fait gagner de la vitesse. */
|
||||||
|
public static final int GAIN_TICKS = 10;
|
||||||
|
/** Gain de vitesse horizontale (blocs par tick) attendu d'une fusée réelle. */
|
||||||
|
public static final double GAIN_MIN = 0.05;
|
||||||
|
/** Au-dessus de cette vitesse (blocs par tick) la fusée n'a plus de gain possible : grâce maintenue. */
|
||||||
|
public static final double VITESSE_FUSEE = 1.6;
|
||||||
|
|
||||||
|
private int graceTicks;
|
||||||
|
private int fenetreGrace;
|
||||||
|
private double vitesseGrace;
|
||||||
|
/** Dernière vitesse mesurée HORS grâce de fusée ; invalide tant que {@link #vitesseConnue} est faux. */
|
||||||
|
private double derniereVitesse;
|
||||||
|
private boolean vitesseConnue;
|
||||||
|
/** Une fenêtre de grâce a échoué au test de gain : pas de nouvelle grâce avant {@link #PAUSE_APRES_REFUS} ticks hors grâce. */
|
||||||
|
private boolean graceRefusee;
|
||||||
|
private int horsGraceTicks;
|
||||||
|
/** Ticks sans fusée exigés après une grâce refusée (≈ une durée de vie de fusée) avant d'en accepter une autre. */
|
||||||
|
public static final int PAUSE_APRES_REFUS = 40;
|
||||||
|
private final double[] fenetre = new double[GAIN_TICKS];
|
||||||
|
/** 0.4.1 : vitesse 3D (horizontale et verticale) des memes ticks : une fusee pousse dans le sens du regard. */
|
||||||
|
private final double[] fenetre3d = new double[GAIN_TICKS];
|
||||||
|
private int monteeTicks;
|
||||||
|
private double vitesseDebut;
|
||||||
|
private int stationnaireTicks;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param m déplacement accepté
|
||||||
|
* @param propulsion une fusée (ou autre poussée connue du serveur) est récente
|
||||||
|
* @return points d'infraction (0 si rien)
|
||||||
|
*/
|
||||||
|
public double enregistrer(EtatMouvement m, boolean propulsion, GardeConfig cfg) {
|
||||||
|
int n = m.ticks();
|
||||||
|
if (m.milieuSpecial() || m.auSolServeur()) {
|
||||||
|
vider();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (propulsion) {
|
||||||
|
// Grâce de fusée : les compteurs sont SUSPENDUS (ni remis à zéro, ni avancés), pas effacés : tirer une fusée
|
||||||
|
// ne blanchit pas une montée ou un plané immobile déjà en cours. Grâce révoquée tôt si la fusée ne
|
||||||
|
// pousse pas réellement (vitesse horizontale sans gain au bout de GAIN_TICKS ticks).
|
||||||
|
if (n >= 1 && n <= TICKS_MAX) {
|
||||||
|
double vh = m.dxz() / n;
|
||||||
|
if (graceRefusee) return mesurer(m, n, cfg); // grâce déjà refusée : pas de nouvelle fenêtre tout de suite
|
||||||
|
if (graceTicks == 0) {
|
||||||
|
// référence = dernière vitesse mesurée hors grâce ; inconnue (atterrissage, milieu spécial,
|
||||||
|
// première mesure) : la vitesse courante, donc le gain exigé part de ce qu'on voit (pessimiste)
|
||||||
|
vitesseGrace = vitesseConnue ? derniereVitesse : vh;
|
||||||
|
fenetreGrace = 0;
|
||||||
|
}
|
||||||
|
graceTicks += n;
|
||||||
|
fenetre3d[fenetreGrace % GAIN_TICKS] = Math.hypot(m.dxz(), m.dy()) / n;
|
||||||
|
fenetre[fenetreGrace++ % GAIN_TICKS] = vh;
|
||||||
|
if (!graceTenue()) {
|
||||||
|
graceRefusee = true;
|
||||||
|
horsGraceTicks = 0;
|
||||||
|
// la fusée ne pousse pas (ou un pic isolé a masqué une vitesse plate) : contrôle comme sans fusée
|
||||||
|
return mesurer(m, n, cfg);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
graceTicks = 0;
|
||||||
|
fenetreGrace = 0;
|
||||||
|
if (graceRefusee && n >= 1 && (horsGraceTicks += n) >= PAUSE_APRES_REFUS) graceRefusee = false;
|
||||||
|
if (n >= 1 && n <= TICKS_MAX) {
|
||||||
|
derniereVitesse = m.dxz() / n; // seulement hors grâce
|
||||||
|
vitesseConnue = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mesurer(m, n, cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nouvelle fusée tirée en plané. Ne remet RIEN à zéro : des fusées enchaînées cumulent leurs ticks de grâce dans la
|
||||||
|
* même fenêtre (sinon un tricheur ne sortirait jamais de la grâce et le test de gain ne serait jamais évalué) et la
|
||||||
|
* référence de vitesse reste celle d'avant la première fusée. La fenêtre ne se ferme que quand le drapeau de
|
||||||
|
* propulsion tombe (paquet hors grâce). Gardée pour le journal d'appel et les tests.
|
||||||
|
*/
|
||||||
|
public void nouvelleFusee() {
|
||||||
|
// volontairement vide
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* La grâce tient tant que la fusée pousse réellement : avant {@link #GAIN_TICKS} ticks, oui ; ensuite la MÉDIANE
|
||||||
|
* des {@link #GAIN_TICKS} derniers ticks (insensible à un pic isolé) doit dépasser d'au moins {@link #GAIN_MIN}
|
||||||
|
* la vitesse d'avant la fusée, ou tous ces ticks doivent rester proches de {@link #VITESSE_FUSEE} (vitesse où la
|
||||||
|
* fusée ne peut plus faire gagner).
|
||||||
|
*/
|
||||||
|
private boolean graceTenue() {
|
||||||
|
if (graceTicks < GAIN_TICKS || fenetreGrace < GAIN_TICKS) return true;
|
||||||
|
double[] v = fenetre.clone();
|
||||||
|
java.util.Arrays.sort(v);
|
||||||
|
double mediane = (v[GAIN_TICKS / 2 - 1] + v[GAIN_TICKS / 2]) / 2.0;
|
||||||
|
double min = v[0];
|
||||||
|
if (mediane >= vitesseGrace + GAIN_MIN || min >= VITESSE_FUSEE * 0.9) return true;
|
||||||
|
// 0.4.1 (faux positif totoche10, dxz 1,3-1,5 dy 0,66-1,04) : en montee avec fusee, la poussee (~1,5-1,7 bloc/tick)
|
||||||
|
// part dans le sens du regard ; la vitesse HORIZONTALE peut rester sous la reference sans que la fusee soit fausse.
|
||||||
|
double min3d = Double.MAX_VALUE;
|
||||||
|
for (double x : fenetre3d) min3d = Math.min(min3d, x);
|
||||||
|
return min3d >= VITESSE_FUSEE * 0.9;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double mesurer(EtatMouvement m, int n, GardeConfig cfg) {
|
||||||
|
if (n < 1 || n > TICKS_MAX) return 0; // neutre : ni remise à zéro ni ajout
|
||||||
|
double vh = m.dxz() / n;
|
||||||
|
double vy = m.dy() / n;
|
||||||
|
double points = 0;
|
||||||
|
|
||||||
|
if (vh < VITESSE_STATIONNAIRE && vy > CHUTE_MIN) stationnaireTicks += n;
|
||||||
|
else stationnaireTicks = 0;
|
||||||
|
if (cfg.elytresStationnaireTicks > 0 && stationnaireTicks > cfg.elytresStationnaireTicks) {
|
||||||
|
points = 1.5;
|
||||||
|
stationnaireTicks = 0; // 0.4.1 : au plus 1,5 point par periode, pas 1,5 par paquet (+30 VL/s en 0.4.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vy > MONTEE_MIN) {
|
||||||
|
if (monteeTicks == 0) vitesseDebut = vh;
|
||||||
|
monteeTicks += n;
|
||||||
|
if (cfg.elytresMonteeTicks > 0 && monteeTicks > cfg.elytresMonteeTicks
|
||||||
|
&& vh >= vitesseDebut * VITESSE_GARDEE) {
|
||||||
|
points = Math.max(points, 1.5);
|
||||||
|
monteeTicks = 0; // 0.4.1 : idem, la periode suivante repart de la vitesse courante
|
||||||
|
}
|
||||||
|
} else if (vy < 0) {
|
||||||
|
monteeTicks = 0;
|
||||||
|
}
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void vider() {
|
||||||
|
graceTicks = 0;
|
||||||
|
fenetreGrace = 0;
|
||||||
|
derniereVitesse = 0;
|
||||||
|
vitesseConnue = false;
|
||||||
|
graceRefusee = false;
|
||||||
|
horsGraceTicks = 0;
|
||||||
|
monteeTicks = 0;
|
||||||
|
vitesseDebut = 0;
|
||||||
|
stationnaireTicks = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -53,8 +53,20 @@ public final class Suivi {
|
|||||||
|
|
||||||
private final Map<Controle, Long> derniereAlerte = new EnumMap<>(Controle.class);
|
private final Map<Controle, Long> derniereAlerte = new EnumMap<>(Controle.class);
|
||||||
|
|
||||||
|
/** Score de suspicion (0.4.0). */
|
||||||
|
public final Suspicion suspicion;
|
||||||
|
/** 0.4.0 : plané, recul, totem. */
|
||||||
|
public final PlaneElytres plane = new PlaneElytres();
|
||||||
|
public final Velocite velocite = new Velocite();
|
||||||
|
public final AutoTotem totem = new AutoTotem();
|
||||||
|
|
||||||
public Suivi(double decroissanceParSeconde) {
|
public Suivi(double decroissanceParSeconde) {
|
||||||
|
this(decroissanceParSeconde, new GardeConfig());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Suivi(double decroissanceParSeconde, GardeConfig cfg) {
|
||||||
this.vl = new VlCompteur(decroissanceParSeconde);
|
this.vl = new VlCompteur(decroissanceParSeconde);
|
||||||
|
this.suspicion = new Suspicion(cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void memoriserPosition(double x, double y, double z, float yaw, float pitch, String dimension) {
|
public void memoriserPosition(double x, double y, double z, float yaw, float pitch, String dimension) {
|
||||||
|
|||||||
@@ -0,0 +1,128 @@
|
|||||||
|
package com.gastinelgarde.core;
|
||||||
|
|
||||||
|
import java.util.EnumMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Score de suspicion d'un joueur, de 0 à 100 (0.4.0). Information pour les humains : ne sanctionne jamais.
|
||||||
|
*
|
||||||
|
* <p>Par contrôle, on garde le plus haut rapport {@code VL / seuilExpulsion} vu (borné à 1), qui décroît avec une
|
||||||
|
* demi-vie ({@link GardeConfig#suspicionDemiVieMinutes}). Le score est la somme de ces rapports multipliés par le
|
||||||
|
* plafond de fiabilité du contrôle (50 / 30 / 15), plafonnée à 100. Les contrôles en OBSERVE comptent. Le VL
|
||||||
|
* lui-même retombe vite (0,5 point/s) et un setback le remet à zéro : on garde donc un pic à part.
|
||||||
|
*
|
||||||
|
* <p>Diversité : au moins {@link GardeConfig#suspicionDiversiteControles} contrôles distincts au palier SETBACK
|
||||||
|
* (mérité, quel que soit le mode) dans la fenêtre = au moins « suspect fort » tant que la fenêtre dure.
|
||||||
|
*
|
||||||
|
* <p>Le temps est fourni par l'appelant (ms, horloge unique par moteur), jamais lu ici.
|
||||||
|
*/
|
||||||
|
public final class Suspicion {
|
||||||
|
|
||||||
|
public enum Niveau { NORMAL, A_SURVEILLER, SUSPECT, SUSPECT_FORT }
|
||||||
|
|
||||||
|
private final GardeConfig cfg;
|
||||||
|
private final Map<Controle, Double> pics = new EnumMap<>(Controle.class);
|
||||||
|
private final Map<Controle, Long> dernierSetback = new EnumMap<>(Controle.class);
|
||||||
|
private long dernierMs = Long.MIN_VALUE;
|
||||||
|
private Niveau notifie = Niveau.NORMAL;
|
||||||
|
private Niveau enAttente;
|
||||||
|
|
||||||
|
public Suspicion(GardeConfig cfg) {
|
||||||
|
this.cfg = cfg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Plafond de contribution du contrôle selon sa fiabilité. */
|
||||||
|
public static double plafond(Controle c, GardeConfig cfg) {
|
||||||
|
return switch (c.fiabilite()) {
|
||||||
|
case 0 -> cfg.suspicionPlafondFiable;
|
||||||
|
case 1 -> cfg.suspicionPlafondMoyen;
|
||||||
|
default -> cfg.suspicionPlafondFaible;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Niveau niveau(double score, GardeConfig cfg) {
|
||||||
|
if (score >= cfg.suspicionSeuilFort) return Niveau.SUSPECT_FORT;
|
||||||
|
if (score >= cfg.suspicionSeuilSuspect) return Niveau.SUSPECT;
|
||||||
|
if (score >= cfg.suspicionSeuilSurveiller) return Niveau.A_SURVEILLER;
|
||||||
|
return Niveau.NORMAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double facteur(long nowMs) {
|
||||||
|
if (dernierMs == Long.MIN_VALUE || nowMs <= dernierMs) return 1.0;
|
||||||
|
double demiVieMs = Math.max(1, cfg.suspicionDemiVieMinutes * 60_000.0);
|
||||||
|
return Math.pow(0.5, (nowMs - dernierMs) / demiVieMs);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void avancer(long nowMs) {
|
||||||
|
double f = facteur(nowMs);
|
||||||
|
if (f != 1.0) pics.replaceAll((k, v) -> v * f);
|
||||||
|
if (dernierMs == Long.MIN_VALUE || nowMs > dernierMs) dernierMs = nowMs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Un verdict est tombé.
|
||||||
|
*
|
||||||
|
* @param vl VL du contrôle après ajout
|
||||||
|
* @param palierSetbackOuPlus le palier mérité est SETBACK ou EXPULSION (mode ignoré)
|
||||||
|
*/
|
||||||
|
public void noter(Controle c, double vl, boolean palierSetbackOuPlus, long nowMs) {
|
||||||
|
if (!cfg.suspicionActive) return;
|
||||||
|
avancer(nowMs);
|
||||||
|
// réarmement avec hystérésis (80 % du premier seuil) : un score qui oscille autour de 25 ne re-notifie pas
|
||||||
|
if (score(nowMs) < cfg.suspicionSeuilSurveiller * 0.8) notifie = Niveau.NORMAL;
|
||||||
|
double ratio = Math.max(0, Math.min(1, vl / Math.max(0.1, cfg.seuilExpulsion)));
|
||||||
|
pics.merge(c, ratio, Math::max);
|
||||||
|
if (palierSetbackOuPlus) dernierSetback.put(c, nowMs);
|
||||||
|
Niveau n = niveau(score(nowMs), cfg);
|
||||||
|
if (n.ordinal() > notifie.ordinal()) {
|
||||||
|
notifie = n;
|
||||||
|
enAttente = n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Nombre de contrôles distincts au palier SETBACK ou plus dans la fenêtre de diversité. */
|
||||||
|
public int controlesDivers(long nowMs) {
|
||||||
|
long fenetre = (long) (cfg.suspicionDiversiteFenetreMinutes * 60_000.0);
|
||||||
|
int n = 0;
|
||||||
|
for (long t : dernierSetback.values()) if (nowMs - t <= fenetre) n++;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Score courant (0 à 100), diversité comprise. */
|
||||||
|
public double score(long nowMs) {
|
||||||
|
double somme = 0;
|
||||||
|
for (Controle c : pics.keySet()) somme += contribution(c, nowMs);
|
||||||
|
double s = Math.min(100.0, somme);
|
||||||
|
if (cfg.suspicionDiversiteControles > 0 && controlesDivers(nowMs) >= cfg.suspicionDiversiteControles) {
|
||||||
|
s = Math.max(s, cfg.suspicionSeuilFort);
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Niveau niveau(long nowMs) {
|
||||||
|
return niveau(score(nowMs), cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Contribution actuelle d'un contrôle (points de score). */
|
||||||
|
public double contribution(Controle c, long nowMs) {
|
||||||
|
Double p = pics.get(c);
|
||||||
|
return p == null ? 0 : p * facteur(nowMs) * plafond(c, cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Nouveau niveau franchi vers le haut depuis le dernier appel (une seule fois), ou null. */
|
||||||
|
public Niveau prendreTransition() {
|
||||||
|
Niveau n = enAttente;
|
||||||
|
enAttente = null;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Texte « vol:40 vitesse:12 » des contributions non nulles, pour le journal. */
|
||||||
|
public String resume(long nowMs) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (Controle c : Controle.values()) {
|
||||||
|
double v = contribution(c, nowMs);
|
||||||
|
if (v >= 0.5) sb.append(sb.length() == 0 ? "" : " ").append(c.id()).append(':').append(Math.round(v));
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
package com.gastinelgarde.core;
|
||||||
|
|
||||||
|
import java.util.ArrayDeque;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contrôle « velocite » (0.4.0) : anti-recul (Anti Knockback) et anti-poussée (Anti Push) de CheatUtils annulent côté
|
||||||
|
* client la vitesse que le serveur vient de donner. Le serveur sait quand il applique un recul (LivingKnockBackEvent,
|
||||||
|
* explosions) et sa force ; il voit ensuite les paquets de mouvement. Vanilla : la vitesse est posée d'un coup
|
||||||
|
* (0,4 de base, plus avec un coup en courant ou Recul) et le joueur recule d'environ 4,5 x la force en 6 ticks. Un
|
||||||
|
* joueur honnête peut contrer en marchant (au plus ~0,22 bloc par tick) ou être arrêté par un mur : un recul
|
||||||
|
* absent n'est donc compté que s'il manque presque tout ({@link GardeConfig#velociteRapportMin}) et seulement
|
||||||
|
* en série ({@link GardeConfig#velociteSerieMin} sur les {@link #HISTORIQUE} derniers reculs de 2 minutes).
|
||||||
|
*
|
||||||
|
* <p>Un second recul pendant la fenêtre, un changement de milieu (eau, véhicule, vol…) ou toute exemption annule la
|
||||||
|
* mesure en cours. Ni sanction ni VL à partir d'un recul isolé.
|
||||||
|
*/
|
||||||
|
public final class Velocite {
|
||||||
|
|
||||||
|
/** Recul vanilla : distance parcourue en 6 ticks / force (frottement 0,91 en l'air : somme des 6 termes ~ 4,8). */
|
||||||
|
public static final double DISTANCE_PAR_FORCE = 4.5;
|
||||||
|
public static final int HISTORIQUE = 6;
|
||||||
|
public static final long VALIDITE_MS = 120_000;
|
||||||
|
|
||||||
|
/** Ticks où le sens du recul est bloqué au-delà desquels la mesure est abandonnée. */
|
||||||
|
public static final int TICKS_BLOQUES_ABANDON = 2;
|
||||||
|
|
||||||
|
private boolean actif;
|
||||||
|
private int ticksBloques;
|
||||||
|
private boolean ambigu;
|
||||||
|
private long debutMs;
|
||||||
|
private double dirX, dirZ, force, parcouru;
|
||||||
|
/** {instant (ms), 1 si le recul est absent}. */
|
||||||
|
private final ArrayDeque<long[]> resultats = new ArrayDeque<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Le serveur vient d'appliquer un recul.
|
||||||
|
*
|
||||||
|
* @param dirX,dirZ direction du déplacement attendu (vecteur unitaire horizontal)
|
||||||
|
* @param force force effective (après résistance au recul)
|
||||||
|
*/
|
||||||
|
public void recul(long nowMs, double dirX, double dirZ, double force, GardeConfig cfg) {
|
||||||
|
if (force < cfg.velociteForceMin) return;
|
||||||
|
double norme = Math.hypot(dirX, dirZ);
|
||||||
|
if (norme < 1e-6) return;
|
||||||
|
if (actif) {
|
||||||
|
ambigu = true; // deuxième recul dans la fenêtre : la mesure ne veut plus rien dire
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
actif = true;
|
||||||
|
ticksBloques = 0;
|
||||||
|
ambigu = false;
|
||||||
|
debutMs = nowMs;
|
||||||
|
this.dirX = dirX / norme;
|
||||||
|
this.dirZ = dirZ / norme;
|
||||||
|
this.force = force;
|
||||||
|
parcouru = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Un paquet de mouvement accepté.
|
||||||
|
*
|
||||||
|
* @param neutre exemption ou milieu qui rend la mesure invalide : la mesure en cours est abandonnée
|
||||||
|
* @return points d'infraction (0 si rien)
|
||||||
|
*/
|
||||||
|
public double mouvement(long nowMs, double dx, double dz, boolean neutre, boolean bloque, GardeConfig cfg) {
|
||||||
|
if (!actif) return 0;
|
||||||
|
if (neutre) {
|
||||||
|
actif = false;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// Obstacle dans le SENS du recul : un seul tick ne suffit pas à annuler la mesure (un mur latéral, ou un
|
||||||
|
// contact d'un tick, ne l'annule jamais) ; deux ticks bloqués ou plus l'abandonnent.
|
||||||
|
if (bloque && ++ticksBloques >= TICKS_BLOQUES_ABANDON) {
|
||||||
|
actif = false;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
parcouru += dx * dirX + dz * dirZ;
|
||||||
|
if (nowMs - debutMs < cfg.velociteFenetreTicks * 50L) return 0;
|
||||||
|
actif = false;
|
||||||
|
if (ambigu) return 0;
|
||||||
|
boolean absent = parcouru < cfg.velociteRapportMin * DISTANCE_PAR_FORCE * force;
|
||||||
|
resultats.addLast(new long[] {nowMs, absent ? 1 : 0});
|
||||||
|
while (resultats.size() > HISTORIQUE || (!resultats.isEmpty() && nowMs - resultats.peekFirst()[0] > VALIDITE_MS)) {
|
||||||
|
resultats.removeFirst();
|
||||||
|
}
|
||||||
|
if (!absent) return 0;
|
||||||
|
int n = 0;
|
||||||
|
for (long[] r : resultats) n += (int) r[1];
|
||||||
|
return n >= cfg.velociteSerieMin ? cfg.velocitePoints : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean actif() { return actif; }
|
||||||
|
|
||||||
|
public double dirX() { return dirX; }
|
||||||
|
|
||||||
|
public double dirZ() { return dirZ; }
|
||||||
|
|
||||||
|
/** Mesure impossible (joueur coincé) : rien n'est compté. */
|
||||||
|
public void abandonner() {
|
||||||
|
actif = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void vider() {
|
||||||
|
actif = false;
|
||||||
|
resultats.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -60,10 +60,12 @@ public final class VolVertical {
|
|||||||
*/
|
*/
|
||||||
public double enregistrer(EtatMouvement e, boolean exempt) {
|
public double enregistrer(EtatMouvement e, boolean exempt) {
|
||||||
int n = e.ticks();
|
int n = e.ticks();
|
||||||
|
// Flottement : évalué avant tout retour anticipé, pour qu'un trou de ticks ne le remette pas à zéro.
|
||||||
|
double ptsFlottement = flottement(exempt || e.milieuSpecial() || e.auSolServeur(), e.dy(), n);
|
||||||
if (n > TICKS_MAX || n < 0) {
|
if (n > TICKS_MAX || n < 0) {
|
||||||
aVitesse = false;
|
aVitesse = false;
|
||||||
avance = 0;
|
avance = 0;
|
||||||
return 0;
|
return ptsFlottement;
|
||||||
}
|
}
|
||||||
boolean enAir = !e.auSolServeur();
|
boolean enAir = !e.auSolServeur();
|
||||||
double dy = e.dy();
|
double dy = e.dy();
|
||||||
@@ -106,6 +108,8 @@ public final class VolVertical {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
points = Math.max(points, ptsFlottement);
|
||||||
|
|
||||||
derniereVitesse = vitesseFin;
|
derniereVitesse = vitesseFin;
|
||||||
aVitesse = true;
|
aVitesse = true;
|
||||||
etaitEnAir = enAir;
|
etaitEnAir = enAir;
|
||||||
@@ -138,6 +142,42 @@ public final class VolVertical {
|
|||||||
return points;
|
return points;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- 0.4.0 : flottement (remplace le « kicked for floating too long » vanilla, coupé par allow-flight=true) ---
|
||||||
|
/** Vanilla : un paquet dont le dy est >= -0,03125 sans appui est « flottant » (ServerGamePacketListenerImpl). */
|
||||||
|
public static final double DY_FLOTTANT = -0.03125;
|
||||||
|
/** Ticks flottants consécutifs avant infraction (80 comme vanilla) ; 0 = coupé. Réglé par le moteur. */
|
||||||
|
int flottementMax;
|
||||||
|
private int flottementTicks;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ticks consécutifs en l'air (sol serveur, hors milieu spécial et exemption) sans vraie chute : un joueur qui
|
||||||
|
* hover, monte lentement ou reste immobile en l'air. Compté en ticks écoulés et non en paquets : un joueur
|
||||||
|
* immobile n'envoie qu'un paquet toutes les 20 ticks. Une vraie chute (dy par tick sous le seuil), le sol, un
|
||||||
|
* milieu spécial ou une exemption remettent le compteur à zéro.
|
||||||
|
*/
|
||||||
|
private double flottement(boolean neutre, double dy, int ticks) {
|
||||||
|
if (flottementMax <= 0) {
|
||||||
|
flottementTicks = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// Remise à zéro seulement sur une preuve : sol confirmé par le serveur, milieu spécial, exemption.
|
||||||
|
if (neutre) {
|
||||||
|
flottementTicks = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// Paquet à 0 tick (doublon, rotation seule) : neutre, ni remise à zéro ni ajout (anti-contournement).
|
||||||
|
if (ticks <= 0) return 0;
|
||||||
|
// Vraie chute (dy par tick sous le seuil vanilla) : preuve que le joueur ne flotte pas.
|
||||||
|
if (dy / ticks < DY_FLOTTANT) {
|
||||||
|
flottementTicks = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// Un trou de plus de TICKS_MAX ticks (lag réel ou simulé) ne remet pas à zéro : il ajoute les ticks écoulés,
|
||||||
|
// au plus TICKS_MAX par paquet (un seul trou, que rien ne confirme, ne suffit pas ; plusieurs, oui).
|
||||||
|
flottementTicks = Math.min(100_000, flottementTicks + Math.min(ticks, TICKS_MAX));
|
||||||
|
return flottementTicks > flottementMax ? 1.5 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
private void viderFenetre() {
|
private void viderFenetre() {
|
||||||
java.util.Arrays.fill(fenetre, false);
|
java.util.Arrays.fill(fenetre, false);
|
||||||
fenetreIndex = 0;
|
fenetreIndex = 0;
|
||||||
@@ -152,6 +192,7 @@ public final class VolVertical {
|
|||||||
etaitEnAir = false;
|
etaitEnAir = false;
|
||||||
anormauxConsecutifs = 0;
|
anormauxConsecutifs = 0;
|
||||||
avance = 0;
|
avance = 0;
|
||||||
|
flottementTicks = 0;
|
||||||
viderFenetre();
|
viderFenetre();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# 0.4.0 : lecture seule des champs prives de la fusee de feu d'artifice, pour n'accorder la grace de propulsion
|
||||||
|
# qu'a une fusee REELLEMENT attachee au joueur en plane (voir GardeEvents.onFusee). Aucune ecriture, aucun comportement change.
|
||||||
|
public net.minecraft.world.entity.projectile.FireworkRocketEntity attachedToEntity
|
||||||
|
public net.minecraft.world.entity.projectile.FireworkRocketEntity lifetime
|
||||||
|
public net.minecraft.world.entity.projectile.FireworkRocketEntity life
|
||||||
@@ -4,7 +4,7 @@ license="MIT"
|
|||||||
|
|
||||||
[[mods]]
|
[[mods]]
|
||||||
modId="gastinelgarde"
|
modId="gastinelgarde"
|
||||||
version="0.3.1"
|
version="0.4.2"
|
||||||
displayName="GastinelGarde"
|
displayName="GastinelGarde"
|
||||||
authors="Théo Gastinel"
|
authors="Théo Gastinel"
|
||||||
description='''Anti-triche maison : combat, cadence, rotation, timer (phase 1), no-fall, vitesse, vol et véhicules (phase 2), points d'infraction avec décroissance, setback puis expulsion, jamais de bannissement automatique. Mod côté serveur uniquement.'''
|
description='''Anti-triche maison : combat, cadence, rotation, timer (phase 1), no-fall, vitesse, vol et véhicules (phase 2), points d'infraction avec décroissance, setback puis expulsion, jamais de bannissement automatique. Mod côté serveur uniquement.'''
|
||||||
|
|||||||
@@ -0,0 +1,123 @@
|
|||||||
|
package com.gastinelgarde;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import com.gastinelgarde.core.Controle;
|
||||||
|
import com.gastinelgarde.core.EtatJoueur;
|
||||||
|
import com.gastinelgarde.core.GardeConfig;
|
||||||
|
import com.gastinelgarde.core.Mode;
|
||||||
|
import com.gastinelgarde.core.Moteur;
|
||||||
|
import com.gastinelgarde.core.Sanction;
|
||||||
|
import com.gastinelgarde.core.Suivi;
|
||||||
|
import com.gastinelgarde.core.Verdict;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
/** Défauts (a) et (b) du 23/10 : analyse reproduite en test, et correctif (b) du motif de sanction. */
|
||||||
|
class CablageSuspicionTest {
|
||||||
|
|
||||||
|
private static Verdict verdict(Controle c, Mode m, Sanction palier, Sanction applicable) {
|
||||||
|
return new Verdict(c, m, 1, 5, palier, applicable, false, "", List.of());
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- (b) motif de la sanction ---
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void b_leMotifEstCeluiDuVerdictQuiSanctionneEtPasLePremierDeLaListe() {
|
||||||
|
// Cas du 23/10 : vitesse en OBSERVE (alerte) en tête de liste, le vol (ENFORCE) déclenche le setback.
|
||||||
|
List<Verdict> vs = List.of(
|
||||||
|
verdict(Controle.VITESSE, Mode.OBSERVE, Sanction.SETBACK, Sanction.ALERTE),
|
||||||
|
verdict(Controle.VOL, Mode.ENFORCE, Sanction.SETBACK, Sanction.SETBACK));
|
||||||
|
assertEquals("vol", Cablage.raison(vs, Sanction.SETBACK));
|
||||||
|
assertEquals("vitesse", Cablage.raison(vs, Sanction.ALERTE));
|
||||||
|
assertEquals("vol", Cablage.raison(vs, Verdict.pire(vs)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void b_journalEtDeconnexionPortentLeBonMotif() {
|
||||||
|
Moteur moteur = new Moteur(new GardeConfig());
|
||||||
|
CablageTest.FauxJoueur p = new CablageTest.FauxJoueur();
|
||||||
|
List<Verdict> vs = List.of(
|
||||||
|
verdict(Controle.VITESSE, Mode.OBSERVE, Sanction.EXPULSION, Sanction.ALERTE),
|
||||||
|
verdict(Controle.REGULARITE, Mode.ENFORCE, Sanction.EXPULSION, Sanction.EXPULSION));
|
||||||
|
Cablage.appliquerSanction(moteur, p, Sanction.EXPULSION, vs);
|
||||||
|
assertEquals("journal Tricheur EXPULSE (regularite)", p.actions.get(0));
|
||||||
|
assertEquals("deconnexion Expulsé par l'anti-triche (regularite).", p.actions.get(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void b_sansVerdictOuSansCorrespondanceExacteRienNeCasse() {
|
||||||
|
assertEquals("anti-triche", Cablage.raison(List.of(), Sanction.EXPULSION));
|
||||||
|
List<Verdict> vs = List.of(verdict(Controle.VOL, Mode.ENFORCE, Sanction.ALERTE, Sanction.ALERTE));
|
||||||
|
assertEquals("vol", Cablage.raison(vs, Sanction.SETBACK), "à défaut, le plus sévère");
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- (a) expulsion « au premier score » après reconnexion : mécanisme prouvé ---
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void a_apresReconnexionLEtatEstNeufMaisLeJournalNeMontrePasLesVerdictsIntermediaires() {
|
||||||
|
GardeConfig cfg = new GardeConfig();
|
||||||
|
cfg.mode(Controle.REGULARITE, Mode.ENFORCE);
|
||||||
|
Moteur moteur = new Moteur(cfg);
|
||||||
|
UUID id = UUID.randomUUID();
|
||||||
|
// Première session terminée par une expulsion, puis reconnexion (GardeEvents.onConnexion).
|
||||||
|
assertTrue(moteur.expulser(id, 0));
|
||||||
|
moteur.oublierExpulsion(id);
|
||||||
|
|
||||||
|
// Reconnexion : Moteur.oublierExpulsion a vidé le suivi (VL à zéro, pas de setback en mémoire).
|
||||||
|
Suivi neuf = moteur.suivi(id);
|
||||||
|
assertEquals(0, neuf.vl.total(0));
|
||||||
|
assertFalse(moteur.estExpulse(id));
|
||||||
|
|
||||||
|
// Le client triche toujours : mêmes coups à 20 par seconde, parfaitement réguliers.
|
||||||
|
Verdict premier = null;
|
||||||
|
Verdict expulsion = null;
|
||||||
|
int nPremier = 0;
|
||||||
|
int n = 0;
|
||||||
|
long debut = 1_000_000;
|
||||||
|
List<Verdict> tous = new ArrayList<>();
|
||||||
|
while (expulsion == null && n < 200) {
|
||||||
|
n++;
|
||||||
|
long now = debut + n * 50L;
|
||||||
|
for (Verdict v : moteur.attaque(id, now, EtatJoueur.normal(), -1, 1, true)) {
|
||||||
|
if (v.controle() != Controle.REGULARITE) continue;
|
||||||
|
tous.add(v);
|
||||||
|
if (premier == null) {
|
||||||
|
premier = v;
|
||||||
|
nPremier = n;
|
||||||
|
}
|
||||||
|
if (v.applicable() == Sanction.EXPULSION) expulsion = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue(premier != null && expulsion != null);
|
||||||
|
// Ce que Théo a lu dans le journal : un premier score de 2,0 au palier JOURNAL...
|
||||||
|
assertEquals(2.0, premier.vl(), 1e-9);
|
||||||
|
assertEquals(Sanction.JOURNAL, premier.palier());
|
||||||
|
// ... puis l'expulsion moins d'une seconde plus tard (10 coups), sans autre ligne de journal car
|
||||||
|
// Suivi.autoriserJournal limite à une ligne par seconde et par contrôle.
|
||||||
|
assertTrue(n - nPremier <= 12, "expulsion " + (n - nPremier) * 50 + " ms après le premier score");
|
||||||
|
long tPremier = debut + nPremier * 50L;
|
||||||
|
long tExpulsion = debut + n * 50L;
|
||||||
|
assertTrue(neuf.autoriserJournal(Controle.REGULARITE, tPremier, 1000));
|
||||||
|
assertFalse(neuf.autoriserJournal(Controle.REGULARITE, tExpulsion, 1000),
|
||||||
|
"la ligne du verdict qui expulse n'est pas écrite");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void a_unJoueurReconnecteEnLAirNAPasDePositionDeRetourDoncPasDeSetback() {
|
||||||
|
Moteur moteur = new Moteur(new GardeConfig());
|
||||||
|
CablageTest.FauxJoueur p = new CablageTest.FauxJoueur();
|
||||||
|
UUID id = p.id();
|
||||||
|
moteur.oublierExpulsion(id); // reconnexion
|
||||||
|
assertFalse(moteur.suivi(id).aPositionValide());
|
||||||
|
List<Verdict> vs = List.of(verdict(Controle.VOL, Mode.ENFORCE, Sanction.SETBACK, Sanction.SETBACK));
|
||||||
|
Cablage.appliquerSanction(moteur, p, Sanction.SETBACK, vs);
|
||||||
|
assertEquals(0, p.compte("teleport"), "pas de position valide : aucun setback possible");
|
||||||
|
assertEquals(0, p.compte("journal"));
|
||||||
|
// Le VL de vol n'est donc pas remis à zéro (apresSetback non appelé) et continue vers l'expulsion.
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -120,6 +120,19 @@ class CablageTest {
|
|||||||
|
|
||||||
// --- Setback (C2, C3) ---
|
// --- Setback (C2, C3) ---
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void v042_setbackVelociteRameneLaPositionEtExpulsionAutoTotemDeconnecte() {
|
||||||
|
Moteur moteur = new Moteur(new GardeConfig());
|
||||||
|
FauxJoueur p = new FauxJoueur();
|
||||||
|
moteur.suivi(ID).memoriserPosition(10.5, 64.0, -3.5, 90f, 10f, MONDE);
|
||||||
|
Cablage.appliquerSanction(moteur, p, Sanction.SETBACK, List.of(verdict(Controle.VELOCITE, Sanction.SETBACK)));
|
||||||
|
assertEquals(List.of("annonce SETBACK", "teleport 10.5 64.0 -3.5 90 10", "journal Tricheur SETBACK (velocite)"),
|
||||||
|
p.actions);
|
||||||
|
Cablage.appliquerSanction(moteur, p, Sanction.EXPULSION, List.of(verdict(Controle.AUTO_TOTEM, Sanction.EXPULSION)));
|
||||||
|
assertEquals(1, p.compte("deconnexion"));
|
||||||
|
assertTrue(moteur.estExpulse(ID));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void C2_setbackVersLaPositionAuSolPuisRemiseAZeroDuVol() {
|
void C2_setbackVersLaPositionAuSolPuisRemiseAZeroDuVol() {
|
||||||
Moteur moteur = new Moteur(new GardeConfig());
|
Moteur moteur = new Moteur(new GardeConfig());
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.gastinelgarde;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
/** Grâce de propulsion d'une fusée (0.4.0, revue de sécurité) : seulement attachée, en plané, vie réelle. */
|
||||||
|
class FuseeElytresTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void fuseeNonAttacheeArbaleteOuPoseeAuSolPasDeGrace() {
|
||||||
|
assertEquals(0, Cablage.graceFusee(false, true, false, 0, 30));
|
||||||
|
assertEquals(0, Cablage.graceFusee(false, false, false, 0, 30));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void fuseeAttacheeSansPlanePasDeGrace() {
|
||||||
|
assertEquals(0, Cablage.graceFusee(true, false, false, 0, 30));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void fuseeRechargeeDuDisquePasDeGrace() {
|
||||||
|
assertEquals(0, Cablage.graceFusee(true, true, true, 0, 30));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void fuseeAttacheeEnPlaneGraceLimiteeALaDureeDeVie() {
|
||||||
|
assertEquals(30 + Cablage.MARGE_FUSEE_TICKS, Cablage.graceFusee(true, true, false, 0, 30));
|
||||||
|
assertEquals(10 + Cablage.MARGE_FUSEE_TICKS, Cablage.graceFusee(true, true, false, 20, 30), "vie restante");
|
||||||
|
assertEquals(Cablage.MARGE_FUSEE_TICKS, Cablage.graceFusee(true, true, false, 50, 30), "déjà finie");
|
||||||
|
assertTrue(Cablage.graceFusee(true, true, false, 0, 100_000) <= Cablage.VIE_FUSEE_MAX + Cablage.MARGE_FUSEE_TICKS, "durée de vie aberrante bornée");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void uneFuseeParSecondeNeDonneJamaisPlusQueLaVieDeLaFusee() {
|
||||||
|
int graceMax = 0;
|
||||||
|
for (int i = 0; i < 20; i++) graceMax = Math.max(graceMax, Cablage.graceFusee(true, true, false, 0, 30));
|
||||||
|
assertTrue(graceMax <= 30 + Cablage.MARGE_FUSEE_TICKS, "chaque grâce vaut la vie de la fusée (~30 ticks) + marge (0.4.1 : 20), pas 120 ticks fixes");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,213 @@
|
|||||||
|
package com.gastinelgarde.core;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0.4.0 : le contrôle vol remplace le « kicked for floating too long » vanilla (allow-flight=true). Flottement =
|
||||||
|
* 80 ticks en l'air sans chute, compté en ticks écoulés. Une exemption par cas listé le 23/10 (rapport).
|
||||||
|
*
|
||||||
|
* Les paquets sont espacés de 20 ticks (rappel de position d'un joueur immobile) pour que le seul contrôle qui
|
||||||
|
* parle soit le flottement : l'ancien contrôle de gravité demande 11 paquets anormaux (220 ticks).
|
||||||
|
*/
|
||||||
|
class FlottementVolTest {
|
||||||
|
|
||||||
|
private GardeConfig cfg;
|
||||||
|
private Moteur moteur;
|
||||||
|
private final UUID joueur = UUID.randomUUID();
|
||||||
|
private long now;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void init() {
|
||||||
|
cfg = new GardeConfig();
|
||||||
|
cfg.mode(Controle.VOL, Mode.ENFORCE);
|
||||||
|
cfg.mode(Controle.VITESSE, Mode.OFF);
|
||||||
|
cfg.mode(Controle.NO_FALL, Mode.OFF);
|
||||||
|
moteur = new Moteur(cfg);
|
||||||
|
now = 100_000;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static EtatMouvement hover(int ticks, boolean milieu, boolean sol) {
|
||||||
|
return new EtatMouvement(0, 0, ticks, sol, sol, false, false, false, 0, 0, milieu, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Envoie n paquets de 20 ticks sans mouvement ; renvoie les points de vol cumulés et le rang du premier. */
|
||||||
|
private double[] hoverPendant(int paquets, EtatJoueur etat, boolean milieu, boolean sol) {
|
||||||
|
double total = 0;
|
||||||
|
int premier = -1;
|
||||||
|
for (int i = 1; i <= paquets; i++) {
|
||||||
|
now += 1000;
|
||||||
|
double pts = moteur.mouvement(joueur, now, etat, hover(20, milieu, sol)).stream()
|
||||||
|
.filter(v -> v.controle() == Controle.VOL).mapToDouble(Verdict::points).sum();
|
||||||
|
if (pts > 0 && premier < 0) premier = i;
|
||||||
|
total += pts;
|
||||||
|
}
|
||||||
|
return new double[] {total, premier};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void hoverImmobileEnSurvieEstVuApres80Ticks() {
|
||||||
|
double[] r = hoverPendant(8, EtatJoueur.normal(), false, false);
|
||||||
|
assertEquals(5, (int) r[1], "4 paquets = 80 ticks tolérés, le 5e dépasse (comme vanilla)");
|
||||||
|
assertTrue(r[0] > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void monteeLenteEstVue() {
|
||||||
|
// +0,02 par tick en l'air, paquets de 1 tick : flottant pour vanilla (dy >= -0,03125)
|
||||||
|
double total = 0;
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
now += 50;
|
||||||
|
EtatMouvement m = new EtatMouvement(0.05, 0.02, 1, false, false, false, false, false, 0, 0, false, false);
|
||||||
|
total += moteur.mouvement(joueur, now, EtatJoueur.normal(), m).stream().mapToDouble(Verdict::points).sum();
|
||||||
|
}
|
||||||
|
assertTrue(total > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void chuteReelleNeCompteJamaisEtRemetLeCompteurAZero() {
|
||||||
|
double total = 0;
|
||||||
|
double vy = 0;
|
||||||
|
for (int i = 0; i < 70; i++) { // 70 ticks de chute libre normale
|
||||||
|
vy = (vy - 0.08) * 0.98;
|
||||||
|
now += 50;
|
||||||
|
EtatMouvement m = new EtatMouvement(0, vy, 1, false, false, false, false, false, 0, 0, false, false);
|
||||||
|
total += moteur.mouvement(joueur, now, EtatJoueur.normal(), m).stream().mapToDouble(Verdict::points).sum();
|
||||||
|
}
|
||||||
|
assertEquals(0, total);
|
||||||
|
// 60 ticks de flottement après une chute : le compteur repart de zéro (60 < 80)
|
||||||
|
double[] r = hoverPendant(3, EtatJoueur.normal(), false, false);
|
||||||
|
assertEquals(0, r[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void sautOrdinaireNEstPasUnFlottement() {
|
||||||
|
double vy = 0.42;
|
||||||
|
double total = 0;
|
||||||
|
for (int i = 0; i < 12; i++) { // saut complet jusqu'à l'atterrissage
|
||||||
|
now += 50;
|
||||||
|
EtatMouvement m = new EtatMouvement(0.2, vy, 1, false, false, true, false, false, 0, 0, false, false);
|
||||||
|
total += moteur.mouvement(joueur, now, EtatJoueur.normal(), m).stream().mapToDouble(Verdict::points).sum();
|
||||||
|
vy = (vy - 0.08) * 0.98;
|
||||||
|
}
|
||||||
|
assertEquals(0, total);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void auSolOuDansUnMilieuSpecialPasDeFlottement() {
|
||||||
|
assertEquals(0, hoverPendant(20, EtatJoueur.normal(), false, true)[0], "debout au sol");
|
||||||
|
// eau, lave, échelles, lianes, échafaudage, toile, neige poudreuse, miel, colonne à bulles, slime, tapis Create
|
||||||
|
assertEquals(0, hoverPendant(20, EtatJoueur.normal(), true, false)[0], "milieu spécial");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void exempt(String nom, Consumer<EtatJoueur.Builder> regle) {
|
||||||
|
Moteur m = new Moteur(cfg);
|
||||||
|
EtatJoueur.Builder b = EtatJoueur.builder();
|
||||||
|
regle.accept(b);
|
||||||
|
EtatJoueur etat = b.build();
|
||||||
|
double total = 0;
|
||||||
|
UUID id = UUID.randomUUID();
|
||||||
|
for (int i = 0; i < 30; i++) {
|
||||||
|
now += 1000;
|
||||||
|
for (Verdict v : m.mouvement(id, now, etat, hover(20, false, false))) total += v.points();
|
||||||
|
}
|
||||||
|
assertEquals(0, total, nom + " doit être exempté du flottement");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void exemptionsExplicites() {
|
||||||
|
exempt("créatif", b -> b.creatif(true));
|
||||||
|
exempt("spectateur", b -> b.spectateur(true));
|
||||||
|
exempt("abilities.mayfly accordé par le serveur", b -> b.peutVoler(true));
|
||||||
|
exempt("élytres (vol plané légitime)", b -> b.elytres(true));
|
||||||
|
exempt("lévitation", b -> b.levitation(true));
|
||||||
|
exempt("chute lente", b -> b.chuteLente(true));
|
||||||
|
exempt("véhicule / passager", b -> b.enVehicule(true));
|
||||||
|
exempt("riptide", b -> b.riptide(true));
|
||||||
|
exempt("structure en mouvement Create / Sable", b -> b.pocheContraption(true));
|
||||||
|
exempt("juste après une téléportation", b -> b.ticksDepuisTeleport(0));
|
||||||
|
exempt("juste après un recul", b -> b.ticksDepuisRecul(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void grandesStructuresLeverUneExemptionRemetLeCompteurAZero() {
|
||||||
|
// 4 paquets sur une structure (exempté), puis il en descend : il faut 80 ticks de plus, pas 0
|
||||||
|
EtatJoueur sur = EtatJoueur.builder().pocheContraption(true).build();
|
||||||
|
hoverPendant(20, sur, false, false);
|
||||||
|
double[] r = hoverPendant(4, EtatJoueur.normal(), false, false);
|
||||||
|
assertEquals(0, r[0], "80 ticks tolérés après la fin de l'exemption");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void reglageAZeroCoupeLeFlottement() {
|
||||||
|
cfg.volFlottementTicks = 0;
|
||||||
|
assertEquals(0, hoverPendant(8, EtatJoueur.normal(), false, false)[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void flottementDansLaListeDesVerdictsParMoteur() {
|
||||||
|
double[] r = hoverPendant(6, EtatJoueur.normal(), false, false);
|
||||||
|
List<Verdict> vs = moteur.mouvement(joueur, now + 1000, EtatJoueur.normal(), hover(20, false, false));
|
||||||
|
assertTrue(r[0] > 0);
|
||||||
|
assertTrue(vs.stream().anyMatch(v -> v.controle() == Controle.VOL));
|
||||||
|
}
|
||||||
|
|
||||||
|
private double pts(EtatMouvement m) {
|
||||||
|
now += 50;
|
||||||
|
return moteur.mouvement(joueur, now, EtatJoueur.normal(), m).stream()
|
||||||
|
.filter(v -> v.controle() == Controle.VOL).mapToDouble(Verdict::points).sum();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void contournement_rafaleDePaquetsAZeroTickNeRemetPasLeCompteurAZero() {
|
||||||
|
for (int i = 0; i < 3; i++) assertEquals(0, pts(hover(20, false, false))); // 60 ticks
|
||||||
|
for (int i = 0; i < 5; i++) assertEquals(0, pts(hover(0, false, false)), "0 tick : neutre, rien n'est ajouté");
|
||||||
|
assertEquals(0, pts(hover(20, false, false)), "80 ticks, pas encore au-dessus");
|
||||||
|
assertTrue(pts(hover(20, false, false)) > 0, "100 ticks : le flottement continue de compter malgré la rafale");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void contournement_rafaleAZeroTickNAjouteRienNonPlus() {
|
||||||
|
for (int i = 0; i < 5; i++) assertEquals(0, pts(hover(0, false, false)));
|
||||||
|
assertEquals(0, pts(hover(20, false, false)), "5 paquets à 0 tick n'ont pas fait monter le compteur");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void contournement_trouDeTicksPlusGrandQueTicksMaxCompteLesTicksEcoules() {
|
||||||
|
for (int i = 0; i < 3; i++) assertEquals(0, pts(hover(20, false, false))); // 60 ticks
|
||||||
|
assertTrue(VolVertical.TICKS_MAX < 60);
|
||||||
|
assertTrue(pts(hover(60, false, false)) > 0, "un trou de 60 ticks (> TICKS_MAX) ajoute 40 : 100 > 80");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void contournement_trouSeulSuffitAuSeuil() {
|
||||||
|
assertEquals(0, pts(hover(100, false, false)), "un seul trou, non confirmé, ajoute au plus TICKS_MAX (40)");
|
||||||
|
pts(hover(100, false, false));
|
||||||
|
assertTrue(pts(hover(100, false, false)) > 0, "des trous répétés comptent");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void remiseAZeroSeulementSurPreuve() {
|
||||||
|
for (int i = 0; i < 3; i++) pts(hover(20, false, false));
|
||||||
|
pts(hover(20, false, true)); // sol confirmé par le serveur
|
||||||
|
for (int i = 0; i < 4; i++) assertEquals(0, pts(hover(20, false, false)));
|
||||||
|
assertTrue(pts(hover(20, false, false)) > 0);
|
||||||
|
|
||||||
|
// vraie chute après un trou : remise à zéro aussi
|
||||||
|
Moteur m2 = new Moteur(cfg);
|
||||||
|
UUID j = UUID.randomUUID();
|
||||||
|
for (int i = 0; i < 3; i++) m2.mouvement(j, now += 1000, EtatJoueur.normal(), hover(20, false, false));
|
||||||
|
m2.mouvement(j, now += 1000, EtatJoueur.normal(),
|
||||||
|
new EtatMouvement(0, -20, 60, false, false, false, false, false, 0, 0, false, false)); // chute, trou 60 ticks
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
assertTrue(m2.mouvement(j, now += 1000, EtatJoueur.normal(), hover(20, false, false)).stream()
|
||||||
|
.noneMatch(v -> v.controle() == Controle.VOL && v.points() > 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,633 @@
|
|||||||
|
package com.gastinelgarde.core;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
/** 0.4.0 : contrôles elytres (Elytra Hack), velocite (Anti Knockback / Anti Push), auto-totem, et bateau. */
|
||||||
|
class NouveauxControlesTest {
|
||||||
|
|
||||||
|
private GardeConfig cfg;
|
||||||
|
private Moteur moteur;
|
||||||
|
private final UUID j = UUID.randomUUID();
|
||||||
|
private long now;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void init() {
|
||||||
|
cfg = new GardeConfig();
|
||||||
|
moteur = new Moteur(cfg);
|
||||||
|
now = 1_000_000;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void modesParDefautTousEnObserve() {
|
||||||
|
for (Controle c : List.of(Controle.ELYTRES, Controle.VELOCITE, Controle.AUTO_TOTEM)) {
|
||||||
|
assertEquals(Mode.OBSERVE, cfg.mode(c), c.id());
|
||||||
|
assertEquals(c == Controle.AUTO_TOTEM ? 0 : 2, c.fiabilite(), c.id() + " : plafond 50 (auto-totem, 0.4.1) ou 15");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Elytres ---
|
||||||
|
|
||||||
|
private double plane(EtatJoueur etat, double dxz, double dy, int ticks) {
|
||||||
|
now += 50L * ticks;
|
||||||
|
EtatMouvement m = new EtatMouvement(dxz, dy, ticks, false, false, false, false, false, 0, 0, false, false);
|
||||||
|
return moteur.mouvement(j, now, etat, m).stream().filter(v -> v.controle() == Controle.ELYTRES)
|
||||||
|
.mapToDouble(Verdict::points).sum();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static EtatJoueur enPlane() {
|
||||||
|
return EtatJoueur.builder().elytres(true).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void elytresMonteeSansPerteDeVitesseEstVue_VanillaFly() {
|
||||||
|
double total = 0;
|
||||||
|
for (int i = 0; i < 40; i++) total += plane(enPlane(), 1.0, 0.4, 1); // monte à vitesse constante
|
||||||
|
assertTrue(total > 0);
|
||||||
|
assertEquals(Mode.OBSERVE, moteur.config().mode(Controle.ELYTRES));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void elytresPlaneImmobileEstVu() {
|
||||||
|
double total = 0;
|
||||||
|
for (int i = 0; i < 40; i++) total += plane(enPlane(), 0.02, 0.0, 1);
|
||||||
|
assertTrue(total > 0, "immobile en plané sans chuter : impossible en vanilla");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void elytresVraiPlaneEtMonteeAvecPerteDeVitesseSontNormaux() {
|
||||||
|
double total = 0;
|
||||||
|
double v = 2.0;
|
||||||
|
for (int i = 0; i < 25; i++) { // piqué puis cabré : la vitesse se transforme en altitude
|
||||||
|
total += plane(enPlane(), v, -0.5, 1);
|
||||||
|
v *= 0.99;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 30; i++) {
|
||||||
|
total += plane(enPlane(), v, 0.35, 1);
|
||||||
|
v *= 0.93; // la montée coûte de la vitesse
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 40; i++) total += plane(enPlane(), 1.0, -0.2, 1); // plané descendant
|
||||||
|
assertEquals(0, total);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void elytresFuseeQuiAccelereVraimentSuspendLesCompteursSansLesEffacer() {
|
||||||
|
double total = 0;
|
||||||
|
for (int i = 0; i < 15; i++) total += plane(enPlane(), 1.0, 0.4, 1); // 15 ticks de montée suspecte
|
||||||
|
assertEquals(0, total, "sous les 20 ticks");
|
||||||
|
EtatJoueur fusee = EtatJoueur.builder().elytres(true).propulsionRecente(true).build();
|
||||||
|
double v = 1.0;
|
||||||
|
for (int i = 0; i < 60; i++) { // la fusée accélère réellement : 1,0 -> 1,6
|
||||||
|
v = Math.min(1.6, v + 0.05);
|
||||||
|
total += plane(fusee, v, 0.4, 1);
|
||||||
|
}
|
||||||
|
assertEquals(0, total, "pendant la grâce rien ne compte");
|
||||||
|
// grâce finie : les 15 ticks d'avant sont conservés, 6 ticks de plus suffisent (> 20)
|
||||||
|
double apres = 0;
|
||||||
|
for (int i = 0; i < 6; i++) apres += plane(enPlane(), 1.6, 0.4, 1);
|
||||||
|
assertTrue(apres > 0, "compteurs conservés, pas remis à zéro par la fusée");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void elytresFuseeQuiNAcceleratPasEstRevoqueeApres10Ticks() {
|
||||||
|
EtatJoueur fusee = EtatJoueur.builder().elytres(true).propulsionRecente(true).build();
|
||||||
|
for (int i = 0; i < 5; i++) plane(enPlane(), 1.0, -0.1, 1); // vitesse d'avant la fusée : 1,0
|
||||||
|
double total = 0;
|
||||||
|
for (int i = 0; i < 60; i++) total += plane(fusee, 1.0, 0.4, 1); // vitesse constante : la fusée ne pousse pas
|
||||||
|
assertTrue(total > 0, "grâce révoquée, la montée à vitesse constante est vue malgré le drapeau");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void elytresFuseeDejaALaVitesseMaximaleGardeLaGrace() {
|
||||||
|
EtatJoueur fusee = EtatJoueur.builder().elytres(true).propulsionRecente(true).build();
|
||||||
|
double total = 0;
|
||||||
|
for (int i = 0; i < 40; i++) total += plane(fusee, 1.8, 0.3, 1);
|
||||||
|
assertEquals(0, total);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void elytresAutreExemptionOuMilieuSpecialEcarteLeControle() {
|
||||||
|
EtatJoueur recul = EtatJoueur.builder().elytres(true).ticksDepuisRecul(0).build();
|
||||||
|
double total = 0;
|
||||||
|
for (int i = 0; i < 60; i++) total += plane(recul, 1.0, 0.4, 1);
|
||||||
|
assertEquals(0, total, "plané + recul : plusieurs raisons, contrôle écarté");
|
||||||
|
for (int i = 0; i < 60; i++) {
|
||||||
|
now += 50;
|
||||||
|
EtatMouvement milieu = new EtatMouvement(1.0, 0.4, 1, false, false, false, false, false, 0, 0, true, false);
|
||||||
|
assertTrue(moteur.mouvement(j, now, enPlane(), milieu).isEmpty(), "courant d'air / bulles / eau");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void elytresPaquetsADeuxTicksEtRafalesNeSontPasMesures() {
|
||||||
|
double total = 0;
|
||||||
|
for (int i = 0; i < 40; i++) total += plane(enPlane(), 1.0, 0.4, 0); // 0 tick : neutre
|
||||||
|
assertEquals(0, total);
|
||||||
|
for (int i = 0; i < 40; i++) total += plane(enPlane(), 3.0, 0.8, 5); // trous : neutre aussi
|
||||||
|
assertEquals(0, total);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void elytresDesactiveParLeMode() {
|
||||||
|
cfg.mode(Controle.ELYTRES, Mode.OFF);
|
||||||
|
double total = 0;
|
||||||
|
for (int i = 0; i < 60; i++) total += plane(enPlane(), 1.0, 0.4, 1);
|
||||||
|
assertEquals(0, total);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void elytresNeSanctionnePasEnObserve() {
|
||||||
|
for (int i = 0; i < 200; i++) {
|
||||||
|
now += 50;
|
||||||
|
EtatMouvement m = new EtatMouvement(1.0, 0.4, 1, false, false, false, false, false, 0, 0, false, false);
|
||||||
|
for (Verdict v : moteur.mouvement(j, now, enPlane(), m)) {
|
||||||
|
assertTrue(v.applicable().ordinal() <= Sanction.ALERTE.ordinal(), v.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Velocite ---
|
||||||
|
|
||||||
|
/** Recul de force 0,4 vers +x ; le joueur se déplace de dx par tick pendant n ticks. */
|
||||||
|
private double recul(double force, double dxParTick, int n, EtatJoueur etat, boolean milieu) {
|
||||||
|
now += 50;
|
||||||
|
moteur.suivi(j);
|
||||||
|
moteur.reculApplique(j, now, 1, 0, force, true);
|
||||||
|
double pts = 0;
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
now += 50;
|
||||||
|
pts += moteur.mesureRecul(j, now, etat, dxParTick, 0, milieu, (x, z) -> false).stream().mapToDouble(Verdict::points).sum();
|
||||||
|
}
|
||||||
|
return pts;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void velociteReculVanillaNEstJamaisUneInfraction() {
|
||||||
|
for (int k = 0; k < 10; k++) {
|
||||||
|
// 0,4 de force : 0,4 puis 0,364... environ 1,8 bloc en 6 ticks
|
||||||
|
assertEquals(0, recul(0.4, 0.3, 7, EtatJoueur.normal(), false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void velociteAntiKnockbackEstVuEnSerieSeulement() {
|
||||||
|
assertEquals(0, recul(0.4, 0.0, 7, EtatJoueur.normal(), false), "1er recul absent : pas de série");
|
||||||
|
assertEquals(0, recul(0.4, 0.0, 7, EtatJoueur.normal(), false), "2e : pas encore");
|
||||||
|
assertTrue(recul(0.4, 0.0, 7, EtatJoueur.normal(), false) > 0, "3e recul absent sur 3 : infraction");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void velociteJoueurContreUnMurFrappeSouventNAJamaisDeVerdict() {
|
||||||
|
// griefing : un tiers coince le joueur contre un mur puis le frappe ; l'adaptateur passe libre = false
|
||||||
|
for (int k = 0; k < 12; k++) {
|
||||||
|
now += 50;
|
||||||
|
moteur.suivi(j);
|
||||||
|
moteur.reculApplique(j, now, 1, 0, 0.4, false);
|
||||||
|
for (int i = 0; i < 7; i++) {
|
||||||
|
now += 50;
|
||||||
|
assertTrue(moteur.mesureRecul(j, now, EtatJoueur.normal(), 0, 0, false, (x, z) -> false).isEmpty());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void velociteJoueurDansUnTrouDUnBlocFrappeNAJamaisDeVerdict() {
|
||||||
|
for (int k = 0; k < 12; k++) {
|
||||||
|
now += 50;
|
||||||
|
moteur.suivi(j);
|
||||||
|
moteur.reculApplique(j, now, 0, 1, 0.9, false);
|
||||||
|
for (int i = 0; i < 7; i++) {
|
||||||
|
now += 50;
|
||||||
|
assertTrue(moteur.mesureRecul(j, now, EtatJoueur.normal(), 0, 0, false, (x, z) -> false).isEmpty());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void velociteJoueurLibreSansReculDonneUnVerdict() {
|
||||||
|
recul(0.4, 0.0, 7, EtatJoueur.normal(), false);
|
||||||
|
recul(0.4, 0.0, 7, EtatJoueur.normal(), false);
|
||||||
|
assertTrue(recul(0.4, 0.0, 7, EtatJoueur.normal(), false) > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Trois reculs de force 0,4 vers +x, joueur immobile ; renvoie les points du dernier, avec un prédicat de blocage. */
|
||||||
|
private double troisReculs(java.util.function.BiPredicate<Double, Double> bloque, java.util.function.IntPredicate tickBloque) {
|
||||||
|
double derniers = 0;
|
||||||
|
for (int k = 0; k < 3; k++) {
|
||||||
|
now += 50;
|
||||||
|
moteur.suivi(j);
|
||||||
|
moteur.reculApplique(j, now, 1, 0, 0.4, true);
|
||||||
|
derniers = 0;
|
||||||
|
int[] tick = {0};
|
||||||
|
for (int i = 0; i < 7; i++) {
|
||||||
|
now += 50;
|
||||||
|
final int t = tick[0]++;
|
||||||
|
derniers += moteur.mesureRecul(j, now, EtatJoueur.normal(), 0, 0, false,
|
||||||
|
(x, z) -> bloque.test(x, z) && tickBloque.test(t)).stream().mapToDouble(Verdict::points).sum();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return derniers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void velociteMurLateralPerpendiculaireAuReculGardeLaMesure() {
|
||||||
|
// le mur est sur l'axe z ; le recul part vers +x : le prédicat directionnel ne le voit pas
|
||||||
|
assertTrue(troisReculs((x, z) -> z != 0, t -> true) > 0, "mesure gardée, verdict à la série");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void velociteMurDansLaDirectionDuReculAbandonneLaMesure() {
|
||||||
|
assertEquals(0, troisReculs((x, z) -> x > 0, t -> true));
|
||||||
|
for (int k = 0; k < 6; k++) assertEquals(0, troisReculs((x, z) -> x > 0, t -> true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void velociteUnSeulTickDeCollisionNAnnulePasLaFenetre() {
|
||||||
|
assertTrue(troisReculs((x, z) -> true, t -> t == 3) > 0, "un tick isolé : mesure gardée");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void velociteGelDuServeurOuTpsBasAbandonneLaMesure() {
|
||||||
|
EtatJoueur gel = EtatJoueur.builder().ticksDepuisGel(10).build();
|
||||||
|
for (int k = 0; k < 6; k++) assertEquals(0, recul(0.4, 0.0, 7, gel, false), "juste après un gel du serveur");
|
||||||
|
EtatJoueur lag = EtatJoueur.builder().tps(10.0).build();
|
||||||
|
for (int k = 0; k < 6; k++) assertEquals(0, recul(0.4, 0.0, 7, lag, false), "serveur qui rame");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void elytresPicIsoleSuiviDUneVitessePlateRetireLaGrace() {
|
||||||
|
for (int i = 0; i < 5; i++) plane(enPlane(), 1.0, -0.1, 1); // vitesse avant la fusée : 1,0
|
||||||
|
EtatJoueur fusee = EtatJoueur.builder().elytres(true).propulsionRecente(true).build();
|
||||||
|
moteur.nouvelleFusee(j);
|
||||||
|
double total = 0;
|
||||||
|
for (int i = 0; i < 60; i++) {
|
||||||
|
double v = i == 2 ? 3.0 : 1.0; // un seul pic, puis plat
|
||||||
|
total += plane(fusee, v, 0.4, 1);
|
||||||
|
}
|
||||||
|
assertTrue(total > 0, "la médiane reste à 1,0 : pas de gain réel, grâce retirée");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void elytresDixFuseesEnchaineesSansGainReelSontRetirees() {
|
||||||
|
EtatJoueur fusee = EtatJoueur.builder().elytres(true).propulsionRecente(true).build();
|
||||||
|
for (int i = 0; i < 5; i++) plane(enPlane(), 1.0, -0.1, 1); // vitesse d'avant : 1,0
|
||||||
|
double total = 0;
|
||||||
|
for (int f = 0; f < 10; f++) {
|
||||||
|
moteur.nouvelleFusee(j); // ne remet rien à zéro
|
||||||
|
for (int i = 0; i < 6; i++) total += plane(fusee, 1.0, 0.4, 1); // le drapeau ne tombe jamais
|
||||||
|
}
|
||||||
|
assertTrue(total > 0, "60 ticks de grâce cumulés sans gain : le test de gain est évalué et retire la grâce");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void elytresGraceRefuseeNeSeReouvrePasAvantUnePause() {
|
||||||
|
EtatJoueur fusee = EtatJoueur.builder().elytres(true).propulsionRecente(true).build();
|
||||||
|
for (int i = 0; i < 5; i++) plane(enPlane(), 1.0, -0.1, 1);
|
||||||
|
for (int i = 0; i < 12; i++) plane(fusee, 1.0, 0.1, 1); // fenêtre sans gain : refusée
|
||||||
|
for (int i = 0; i < 5; i++) plane(enPlane(), 1.0, -0.1, 1); // le drapeau tombe 5 ticks seulement
|
||||||
|
double total = 0;
|
||||||
|
for (int i = 0; i < 40; i++) total += plane(fusee, 1.0, 0.4, 1); // nouvelle fusée aussitôt : pas de grâce
|
||||||
|
assertTrue(total > 0, "nouvelle fenêtre refusée tant que la pause n'est pas écoulée");
|
||||||
|
// après une vraie pause, une fusée qui accélère est de nouveau acceptée
|
||||||
|
for (int i = 0; i < 50; i++) plane(enPlane(), 1.0, -0.1, 1);
|
||||||
|
double v = 1.0, apres = 0;
|
||||||
|
for (int i = 0; i < 12; i++) apres += plane(fusee, v += 0.06, 0.4, 1);
|
||||||
|
assertEquals(0, apres);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void elytresAtterrissagePuisDecollageAvecFuseePasDeVieilleReference() {
|
||||||
|
// vitesse élevée en plané, puis atterrissage (sol serveur) : la référence est effacée
|
||||||
|
for (int i = 0; i < 10; i++) plane(enPlane(), 2.5, -0.1, 1);
|
||||||
|
now += 50;
|
||||||
|
moteur.mouvement(j, now, EtatJoueur.normal(), new EtatMouvement(0, 0, 1, true, true, false, false, false, 0, 0, false, false));
|
||||||
|
// décollage lent avec fusée : sans vieille référence de 2,5, un vrai gain (0,6 -> 1,2) garde la grâce
|
||||||
|
EtatJoueur fusee = EtatJoueur.builder().elytres(true).propulsionRecente(true).build();
|
||||||
|
double total = 0;
|
||||||
|
double v = 0.6;
|
||||||
|
for (int i = 0; i < 40; i++) total += plane(fusee, v = Math.min(1.5, v + 0.05), 0.4, 1);
|
||||||
|
assertEquals(0, total, "gain réel mesuré contre une référence inconnue, pas contre l'ancienne vitesse de 2,5");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void velociteEtAutoTotemJamaisDeSanctionEnObserve() { // 0.4.2 : en ENFORCE, voir Sanctions042Test
|
||||||
|
cfg.mode(Controle.VELOCITE, Mode.OBSERVE);
|
||||||
|
cfg.mode(Controle.AUTO_TOTEM, Mode.OBSERVE);
|
||||||
|
boolean vu = false;
|
||||||
|
for (int k = 0; k < 40; k++) {
|
||||||
|
now += 50;
|
||||||
|
moteur.suivi(j);
|
||||||
|
moteur.reculApplique(j, now, 1, 0, 0.4, true);
|
||||||
|
for (int i = 0; i < 7; i++) {
|
||||||
|
now += 50;
|
||||||
|
for (Verdict v : moteur.mesureRecul(j, now, EtatJoueur.normal(), 0, 0, false, (x, z) -> false)) {
|
||||||
|
vu = true;
|
||||||
|
assertTrue(v.applicable().ordinal() <= Sanction.ALERTE.ordinal(), v.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue(vu);
|
||||||
|
boolean totemVu = false;
|
||||||
|
for (int k = 0; k < 30; k++) {
|
||||||
|
moteur.totemEclate(j, now += 1000, false);
|
||||||
|
for (Verdict v : moteur.totemEnMain(j, now += 50, EtatJoueur.normal(), true)) {
|
||||||
|
totemVu = true;
|
||||||
|
assertTrue(v.applicable().ordinal() <= Sanction.ALERTE.ordinal(), v.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue(totemVu);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void velociteUnMurOuUnContreIsoleNeSuffitPas() {
|
||||||
|
assertEquals(0, recul(0.4, 0.0, 7, EtatJoueur.normal(), false)); // contre un mur
|
||||||
|
assertEquals(0, recul(0.4, 0.3, 7, EtatJoueur.normal(), false)); // recul normal
|
||||||
|
assertEquals(0, recul(0.4, 0.0, 7, EtatJoueur.normal(), false)); // contre un mur encore
|
||||||
|
assertEquals(0, recul(0.4, 0.3, 7, EtatJoueur.normal(), false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void velociteTraceReelleDElytresHonnetesSansInfractionElytres() throws Exception {
|
||||||
|
// trace du 15/10 : plané honnête (fusées comprises, non marquées dans la trace : on ne vérifie que la montée)
|
||||||
|
List<String> lignes = java.nio.file.Files.readAllLines(java.nio.file.Path.of(
|
||||||
|
NouveauxControlesTest.class.getResource("/traces/elytres-2026-10-15.jsonl").toURI()));
|
||||||
|
Rejeu.Resume r = Rejeu.rejouer(lignes, new GardeConfig());
|
||||||
|
System.out.println("ELYTRES-HONNETE infractions=" + r.infractions() + " exemples=" + r.exemples());
|
||||||
|
assertTrue(r.mouvements() > 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void velociteJoueurQuiContreEnMarchantEnArriereReculeEncore() {
|
||||||
|
// marche à 0,22 bloc par tick dans le sens opposé : recul net 0,4 + ... > 15 % du recul attendu
|
||||||
|
for (int k = 0; k < 6; k++) assertEquals(0, recul(0.9, 0.25, 7, EtatJoueur.normal(), false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void velociteExemptionsEtMilieux() {
|
||||||
|
List<EtatJoueur> etats = List.of(
|
||||||
|
EtatJoueur.builder().creatif(true).build(),
|
||||||
|
EtatJoueur.builder().spectateur(true).build(),
|
||||||
|
EtatJoueur.builder().peutVoler(true).build(),
|
||||||
|
EtatJoueur.builder().elytres(true).build(),
|
||||||
|
EtatJoueur.builder().enVehicule(true).build(),
|
||||||
|
EtatJoueur.builder().riptide(true).build(),
|
||||||
|
EtatJoueur.builder().pocheContraption(true).build(),
|
||||||
|
EtatJoueur.builder().ticksDepuisTeleport(0).build());
|
||||||
|
for (EtatJoueur e : etats) {
|
||||||
|
for (int k = 0; k < 6; k++) assertEquals(0, recul(0.4, 0.0, 7, e, false), e.toString());
|
||||||
|
}
|
||||||
|
for (int k = 0; k < 6; k++) assertEquals(0, recul(0.4, 0.0, 7, EtatJoueur.normal(), true), "eau, échelle…");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void velociteDeuxReculsDansLaFenetreOuForceNegligeableAnnulentLaMesure() {
|
||||||
|
for (int k = 0; k < 5; k++) {
|
||||||
|
now += 50;
|
||||||
|
moteur.reculApplique(j, now, 1, 0, 0.4, true);
|
||||||
|
moteur.reculApplique(j, now + 50, 1, 0, 0.4, true); // second coup pendant la fenêtre
|
||||||
|
for (int i = 0; i < 7; i++) {
|
||||||
|
now += 50;
|
||||||
|
assertTrue(moteur.mesureRecul(j, now, EtatJoueur.normal(), 0, 0, false, (x, z) -> false).isEmpty());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int k = 0; k < 5; k++) assertEquals(0, recul(0.05, 0.0, 7, EtatJoueur.normal(), false), "force < 0,15");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void velociteAnciennesMesuresExpirent() {
|
||||||
|
recul(0.4, 0.0, 7, EtatJoueur.normal(), false);
|
||||||
|
recul(0.4, 0.0, 7, EtatJoueur.normal(), false);
|
||||||
|
now += Velocite.VALIDITE_MS + 1000;
|
||||||
|
assertEquals(0, recul(0.4, 0.0, 7, EtatJoueur.normal(), false), "les deux premiers ont plus de 2 minutes");
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Auto-totem ---
|
||||||
|
|
||||||
|
private double totem(long delaiMs, int ping, boolean reserve) {
|
||||||
|
Moteur m = new Moteur(cfg);
|
||||||
|
UUID id = UUID.randomUUID();
|
||||||
|
m.suivi(id);
|
||||||
|
long t = 5_000_000;
|
||||||
|
m.totemEclate(id, t, reserve);
|
||||||
|
EtatJoueur e = EtatJoueur.builder().pingMs(ping).build();
|
||||||
|
double pts = 0;
|
||||||
|
for (long d = 50; d <= delaiMs + 200; d += 50) {
|
||||||
|
boolean enMain = d >= delaiMs;
|
||||||
|
pts += m.totemEnMain(id, t + d, e, enMain).stream().mapToDouble(Verdict::points).sum();
|
||||||
|
}
|
||||||
|
return pts;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void autoTotemRemisInstantanementEstVu() {
|
||||||
|
assertTrue(totem(50, 30, false) > 0);
|
||||||
|
assertTrue(totem(100, 30, false) > 0, "100 ms < 150 + 30");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void autoTotemDelaiHumainNormal() {
|
||||||
|
assertEquals(0, totem(300, 30, false));
|
||||||
|
assertEquals(0, totem(250, 50, false));
|
||||||
|
assertEquals(0, totem(2000, 30, false), "totem remis bien plus tard");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void autoTotemLePingNEntreQueBorne() {
|
||||||
|
assertEquals(0, totem(250, 100, false), "250 >= 150 + 100");
|
||||||
|
// ping annoncé de 5 s : seulement 200 ms de marge au plus (150 + 200 = 350)
|
||||||
|
assertTrue(totem(300, 5000, false) > 0);
|
||||||
|
assertEquals(0, totem(400, 5000, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void autoTotemTotemDeReserveEnMainAnnuleLaMesure() {
|
||||||
|
assertEquals(0, totem(50, 30, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void autoTotemAucunTotemRemisOuTropTardNeCompteRien() {
|
||||||
|
Moteur m = new Moteur(cfg);
|
||||||
|
UUID id = UUID.randomUUID();
|
||||||
|
m.suivi(id);
|
||||||
|
m.totemEclate(id, 1000, false);
|
||||||
|
EtatJoueur e = EtatJoueur.normal();
|
||||||
|
assertTrue(m.totemEnMain(id, 1050, e, false).isEmpty());
|
||||||
|
assertTrue(m.totemEnMain(id, 1000 + AutoTotem.EXPIRATION_MS + 50, e, true).isEmpty(), "mesure expirée");
|
||||||
|
// un totem ramassé bien après, sans nouvel éclatement : rien
|
||||||
|
assertTrue(m.totemEnMain(id, 1000 + AutoTotem.EXPIRATION_MS + 100, e, true).isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void autoTotemMemeTickQueLEclatementNeCompteRien() {
|
||||||
|
Moteur m = new Moteur(cfg);
|
||||||
|
UUID id = UUID.randomUUID();
|
||||||
|
m.suivi(id);
|
||||||
|
m.totemEclate(id, 1000, false);
|
||||||
|
assertTrue(m.totemEnMain(id, 1000, EtatJoueur.normal(), true).isEmpty(), "totem encore compté dans la main");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void autoTotemOffEtObserve() {
|
||||||
|
cfg.mode(Controle.AUTO_TOTEM, Mode.OFF);
|
||||||
|
assertEquals(0, totem(50, 30, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Bateau (Boat Hack : friction 0,99) ---
|
||||||
|
|
||||||
|
private static EtatVehicule bateau(double dxz, boolean glace) {
|
||||||
|
return new EtatVehicule(EtatVehicule.Type.BATEAU, dxz, 0, 1, false, true, glace, 0, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void bateauVanillaSurEauNEstJamaisVu() {
|
||||||
|
VehiculeMouvement v = new VehiculeMouvement();
|
||||||
|
double pts = 0;
|
||||||
|
for (int i = 0; i < 400; i++) pts += v.vitesse(bateau(0.40, false), 1.0, 1.5);
|
||||||
|
assertEquals(0, pts);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void bateauSurGlaceBleueVanillaNEstJamaisVu() {
|
||||||
|
VehiculeMouvement v = new VehiculeMouvement();
|
||||||
|
double pts = 0;
|
||||||
|
for (int i = 0; i < 400; i++) pts += v.vitesse(bateau(3.6, true), 1.0, 1.5);
|
||||||
|
assertEquals(0, pts);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void bateauFriction099EstVuEnQuelquesTicks() {
|
||||||
|
VehiculeMouvement v = new VehiculeMouvement();
|
||||||
|
int premier = -1;
|
||||||
|
for (int i = 0; i < 60 && premier < 0; i++) {
|
||||||
|
// boat hack : l'eau garde 99 % de la vitesse, l'accélération 0,04 par tick s'accumule vers 4 blocs par tick
|
||||||
|
double dxz = Math.min(4.0, 0.4 + 0.04 * i / 0.01 * 0.1);
|
||||||
|
if (v.vitesse(bateau(dxz, false), 1.0, 1.5) > 0) premier = i;
|
||||||
|
}
|
||||||
|
assertTrue(premier >= 0 && premier < 40, "premier point au tick " + premier);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void bateauLegerementTropRapideSeVoitAuBoutDeQuelquesSecondes() {
|
||||||
|
// 0,479 bloc/tick (valeur du journal du 23/10) : 0,03 au-dessus de la borne de 0,45, il faut du temps
|
||||||
|
VehiculeMouvement v = new VehiculeMouvement();
|
||||||
|
double pts = 0;
|
||||||
|
for (int i = 0; i < 20; i++) pts += v.vitesse(bateau(0.479, false), 1.0, 1.5);
|
||||||
|
assertEquals(0, pts, "20 ticks à 0,479 : 0,6 bloc d'excès cumulé, sous le seuil de 1,5");
|
||||||
|
for (int i = 0; i < 100; i++) pts += v.vitesse(bateau(0.479, false), 1.0, 1.5);
|
||||||
|
assertTrue(pts > 0, "soutenu 6 s, cela compte");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void controlesNouveauxPrisEnCompteParLeScoreDeSuspicion() {
|
||||||
|
// auto-totem seul ne rend jamais suspect (plafond 15) ; les trois ensemble restent sous 50
|
||||||
|
Suspicion s = new Suspicion(cfg);
|
||||||
|
s.noter(Controle.AUTO_TOTEM, 99, false, 0);
|
||||||
|
s.noter(Controle.VELOCITE, 99, false, 0);
|
||||||
|
s.noter(Controle.ELYTRES, 99, false, 0);
|
||||||
|
assertEquals(80, s.score(0), 1e-9); // 0.4.1 : auto-totem fiable (plafond 50) : 50 + 15 + 15
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- 0.4.1 ---
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void v041_autoTotemContinueApresPassageEnEnforceSansSanctionReelle() {
|
||||||
|
for (int k = 0; k < 5; k++) {
|
||||||
|
now += 5000;
|
||||||
|
moteur.totemEclate(j, now, false);
|
||||||
|
now += 50;
|
||||||
|
moteur.totemEnMain(j, now, EtatJoueur.normal(), true);
|
||||||
|
}
|
||||||
|
cfg.mode(Controle.AUTO_TOTEM, Mode.ENFORCE); // ce que fait /garde mode ou /garde reload sur la meme config
|
||||||
|
int vus = 0;
|
||||||
|
for (int k = 0; k < 10; k++) {
|
||||||
|
now += 5000;
|
||||||
|
moteur.totemEclate(j, now, false);
|
||||||
|
now += 50;
|
||||||
|
for (Verdict v : moteur.totemEnMain(j, now, EtatJoueur.normal(), true)) {
|
||||||
|
vus++;
|
||||||
|
assertEquals(Mode.ENFORCE, v.mode());
|
||||||
|
assertTrue(v.applicable() != Sanction.SETBACK, "0.4.2 : auto-totem n'a pas de setback (expulsion possible)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertEquals(10, vus, "les detections continuent en ENFORCE");
|
||||||
|
assertFalse(moteur.estExpulse(j));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void v041_velociteSixReculsAbsentsEspacesDe3sDepassentLeSetback() {
|
||||||
|
assertEquals(4.0, cfg.velocitePoints, 1e-9, "defaut 0.4.1");
|
||||||
|
double vlMax = 0;
|
||||||
|
for (int k = 0; k < 6; k++) {
|
||||||
|
now += 3000 - 50L * 8; // ~3 s entre deux coups
|
||||||
|
now += 50;
|
||||||
|
moteur.reculApplique(j, now, 1, 0, 0.4, true);
|
||||||
|
for (int i = 0; i < 7; i++) {
|
||||||
|
now += 50;
|
||||||
|
for (Verdict v : moteur.mesureRecul(j, now, EtatJoueur.normal(), 0, 0, false, (x, z) -> false)) {
|
||||||
|
vlMax = Math.max(vlMax, v.vl());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue(vlMax > cfg.seuilSetback, "vl max " + vlMax + " doit depasser " + cfg.seuilSetback);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void v041_velocitePointsConfigurables() {
|
||||||
|
cfg.velocitePoints = 2.0; // comportement 0.4.0 : plafonne sous le setback
|
||||||
|
double vlMax = 0;
|
||||||
|
for (int k = 0; k < 6; k++) {
|
||||||
|
now += 2600;
|
||||||
|
moteur.reculApplique(j, now, 1, 0, 0.4, true);
|
||||||
|
for (int i = 0; i < 7; i++) {
|
||||||
|
now += 50;
|
||||||
|
for (Verdict v : moteur.mesureRecul(j, now, EtatJoueur.normal(), 0, 0, false, (x, z) -> false)) {
|
||||||
|
vlMax = Math.max(vlMax, v.vl());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue(vlMax < cfg.seuilSetback, "2 points : " + vlMax);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void v041_elytresMonteeAvecFuseeJournalTotoche10SansInfraction() {
|
||||||
|
// journal reel : plane rapide (reference hors grace ~1,5), puis fusee en montee : dxz 1,30-1,52, dy 0,66-1,04
|
||||||
|
for (int i = 0; i < 10; i++) plane(enPlane(), 1.55, -0.2, 1);
|
||||||
|
EtatJoueur fusee = EtatJoueur.builder().elytres(true).propulsionRecente(true).build();
|
||||||
|
double[][] journal = {{1.300, 1.039}, {1.520, 0.658}, {1.456, 0.807}};
|
||||||
|
double total = 0;
|
||||||
|
for (int i = 0; i < 45; i++) {
|
||||||
|
double[] p = journal[i % 3];
|
||||||
|
total += plane(fusee, p[0], p[1], 1);
|
||||||
|
}
|
||||||
|
assertEquals(0, total, 1e-9, "fusee reelle en montee : aucune infraction");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void v041_elytresVlNeMontePlusDe1Point5ParPaquet() {
|
||||||
|
double vlMax = 0;
|
||||||
|
for (int i = 0; i < 20; i++) plane(enPlane(), 1.0, 0.4, 1); // periode de montee suspecte
|
||||||
|
for (int i = 0; i < 20; i++) {
|
||||||
|
now += 50;
|
||||||
|
EtatMouvement m = new EtatMouvement(1.0, 0.4, 1, false, false, false, false, false, 0, 0, false, false);
|
||||||
|
for (Verdict v : moteur.mouvement(j, now, enPlane(), m)) vlMax = Math.max(vlMax, v.vl());
|
||||||
|
}
|
||||||
|
assertTrue(vlMax > 0, "VanillaFly toujours vu");
|
||||||
|
assertTrue(vlMax <= 3.0, "au plus 1,5 point par periode de " + cfg.elytresMonteeTicks + " ticks : " + vlMax);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void v041_elytresFuseeSansPousseeToujoursRevoquee() {
|
||||||
|
EtatJoueur fusee = EtatJoueur.builder().elytres(true).propulsionRecente(true).build();
|
||||||
|
for (int i = 0; i < 5; i++) plane(enPlane(), 1.0, -0.1, 1);
|
||||||
|
double total = 0;
|
||||||
|
for (int i = 0; i < 60; i++) total += plane(fusee, 1.0, 0.4, 1); // 3D 1,08 < 1,44 : pas une vraie fusee
|
||||||
|
assertTrue(total > 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
package com.gastinelgarde.core;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
/** 0.4.2 : vraies sanctions pour auto-totem et velocite, seuils propres a ces controles. */
|
||||||
|
class Sanctions042Test {
|
||||||
|
|
||||||
|
private GardeConfig cfg;
|
||||||
|
private Moteur moteur;
|
||||||
|
private final UUID j = UUID.randomUUID();
|
||||||
|
private long now;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void init() {
|
||||||
|
cfg = new GardeConfig();
|
||||||
|
moteur = new Moteur(cfg);
|
||||||
|
now = 1_000_000;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void seuilsParDefaut() {
|
||||||
|
assertEquals(9, cfg.autoTotemSeuilExpulsion, 1e-9);
|
||||||
|
assertEquals(8, cfg.velociteSeuilSetback, 1e-9);
|
||||||
|
assertEquals(16, cfg.velociteSeuilExpulsion, 1e-9);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void paliersVelocite() {
|
||||||
|
assertEquals(Sanction.ALERTE, Paliers.palier(7.9, cfg, Controle.VELOCITE));
|
||||||
|
assertEquals(Sanction.SETBACK, Paliers.palier(8, cfg, Controle.VELOCITE));
|
||||||
|
assertEquals(Sanction.SETBACK, Paliers.palier(15.9, cfg, Controle.VELOCITE));
|
||||||
|
assertEquals(Sanction.EXPULSION, Paliers.palier(16, cfg, Controle.VELOCITE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void paliersAutoTotem() {
|
||||||
|
assertEquals(Sanction.EXPULSION, Paliers.palier(9, cfg, Controle.AUTO_TOTEM));
|
||||||
|
assertTrue(Paliers.palier(8.9, cfg, Controle.AUTO_TOTEM).ordinal() < Sanction.EXPULSION.ordinal());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void seuilsAZeroRetombentSurLesSeuilsGlobaux() {
|
||||||
|
cfg.velociteSeuilSetback = 0;
|
||||||
|
cfg.velociteSeuilExpulsion = 0;
|
||||||
|
cfg.autoTotemSeuilExpulsion = 0;
|
||||||
|
for (double vl : new double[] {3, 9, 12, 15, 25}) {
|
||||||
|
assertEquals(Paliers.palier(vl, cfg), Paliers.palier(vl, cfg, Controle.VELOCITE));
|
||||||
|
assertEquals(Paliers.palier(vl, cfg), Paliers.palier(vl, cfg, Controle.AUTO_TOTEM));
|
||||||
|
}
|
||||||
|
cfg.velociteSeuilSetback = 8;
|
||||||
|
assertEquals(Paliers.palier(9, cfg), Paliers.palier(9, cfg, Controle.VITESSE), "autres controles inchanges");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void sanctionMaxResteRespecte() {
|
||||||
|
cfg.sanctionMax = Sanction.SETBACK;
|
||||||
|
assertEquals(Sanction.SETBACK, Paliers.palier(50, cfg, Controle.VELOCITE));
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Verdict> totem() {
|
||||||
|
moteur.totemEclate(j, now, false);
|
||||||
|
now += 50;
|
||||||
|
return moteur.totemEnMain(j, now, EtatJoueur.normal(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void autoTotemEnforceExpulseSansJamaisDeSetback() {
|
||||||
|
cfg.mode(Controle.AUTO_TOTEM, Mode.ENFORCE);
|
||||||
|
Sanction pire = Sanction.AUCUNE;
|
||||||
|
int detections = 0;
|
||||||
|
for (int k = 0; k < 6 && pire != Sanction.EXPULSION; k++) {
|
||||||
|
for (Verdict v : totem()) {
|
||||||
|
detections++;
|
||||||
|
assertTrue(v.applicable() != Sanction.SETBACK, "palier SETBACK ramene a ALERTE");
|
||||||
|
if (v.applicable().ordinal() > pire.ordinal()) pire = v.applicable();
|
||||||
|
}
|
||||||
|
now += 300; // detections rapprochees
|
||||||
|
}
|
||||||
|
assertEquals(Sanction.EXPULSION, pire);
|
||||||
|
assertTrue(detections <= 4, "expulsion a la 3e ou 4e detection rapprochee : " + detections);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void autoTotemEnObserveJamaisDeSanction() {
|
||||||
|
for (int k = 0; k < 10; k++) {
|
||||||
|
for (Verdict v : totem()) assertTrue(v.applicable().ordinal() <= Sanction.ALERTE.ordinal());
|
||||||
|
now += 300;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Sanction recul() {
|
||||||
|
now += 2000;
|
||||||
|
moteur.reculApplique(j, now, 1, 0, 0.4, true);
|
||||||
|
Sanction pire = Sanction.AUCUNE;
|
||||||
|
for (int i = 0; i < 7; i++) {
|
||||||
|
now += 50;
|
||||||
|
for (Verdict v : moteur.mesureRecul(j, now, EtatJoueur.normal(), 0, 0, false, (x, z) -> false)) {
|
||||||
|
if (v.applicable().ordinal() > pire.ordinal()) pire = v.applicable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pire;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void velociteEnforceSetbackPuisExpulsion() {
|
||||||
|
cfg.mode(Controle.VELOCITE, Mode.ENFORCE);
|
||||||
|
cfg.setbacksAvantExpulsion = 0; // isole les seuils de velocite (C5 teste ailleurs)
|
||||||
|
boolean setback = false;
|
||||||
|
Sanction s = Sanction.AUCUNE;
|
||||||
|
for (int k = 0; k < 20 && s != Sanction.EXPULSION; k++) {
|
||||||
|
s = recul();
|
||||||
|
if (s == Sanction.SETBACK) setback = true;
|
||||||
|
}
|
||||||
|
assertTrue(setback, "retour en arriere avant l'expulsion");
|
||||||
|
assertEquals(Sanction.EXPULSION, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void velociteEnObserveJamaisDeSanction() {
|
||||||
|
for (int k = 0; k < 20; k++) assertTrue(recul().ordinal() <= Sanction.ALERTE.ordinal());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,294 @@
|
|||||||
|
package com.gastinelgarde.core;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
|
||||||
|
/** Score de suspicion 0-100 (0.4.0) : contributions, plafonds, décroissance, diversité, paliers, historique. */
|
||||||
|
class SuspicionTest {
|
||||||
|
|
||||||
|
private static final long MIN = 60_000L;
|
||||||
|
|
||||||
|
private GardeConfig cfg;
|
||||||
|
private Suspicion s;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void init() {
|
||||||
|
cfg = new GardeConfig();
|
||||||
|
s = new Suspicion(cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void valeursParDefautDeLaConception() {
|
||||||
|
assertEquals(25, cfg.suspicionSeuilSurveiller);
|
||||||
|
assertEquals(50, cfg.suspicionSeuilSuspect);
|
||||||
|
assertEquals(75, cfg.suspicionSeuilFort);
|
||||||
|
assertEquals(10, cfg.suspicionDemiVieMinutes);
|
||||||
|
assertEquals(50, cfg.suspicionPlafondFiable);
|
||||||
|
assertEquals(30, cfg.suspicionPlafondMoyen);
|
||||||
|
assertEquals(15, cfg.suspicionPlafondFaible);
|
||||||
|
assertEquals(3, cfg.suspicionDiversiteControles);
|
||||||
|
assertEquals(10, cfg.suspicionDiversiteFenetreMinutes);
|
||||||
|
assertEquals(7, cfg.suspicionHistoriqueJours);
|
||||||
|
assertTrue(cfg.suspicionActive);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void fiabiliteDeChaqueControle() {
|
||||||
|
List<Controle> fiables = List.of(Controle.VOL, Controle.VITESSE, Controle.NO_FALL, Controle.PORTEE,
|
||||||
|
Controle.HITBOX, Controle.REGULARITE, Controle.AUTO_TOTEM);
|
||||||
|
List<Controle> moyens = List.of(Controle.COUPS_HORS_BOITE, Controle.KILLAURA_ANGLE, Controle.KILLAURA_CIBLES,
|
||||||
|
Controle.CADENCE);
|
||||||
|
for (Controle c : Controle.values()) {
|
||||||
|
double attendu = fiables.contains(c) ? 50 : moyens.contains(c) ? 30 : 15;
|
||||||
|
assertEquals(attendu, Suspicion.plafond(c, cfg), c.id());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void contributionNormaliseeParLeSeuilDExpulsionEtPlafonnee() {
|
||||||
|
s.noter(Controle.VOL, 10, false, 0); // moitié du seuil d'expulsion (20)
|
||||||
|
assertEquals(25, s.score(0), 1e-9);
|
||||||
|
s.noter(Controle.VOL, 20, false, 0);
|
||||||
|
assertEquals(50, s.score(0), 1e-9);
|
||||||
|
s.noter(Controle.VOL, 5000, false, 0); // au-delà : plafonné
|
||||||
|
assertEquals(50, s.score(0), 1e-9);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void plafondsParFiabilite() {
|
||||||
|
s.noter(Controle.CADENCE, 999, false, 0);
|
||||||
|
assertEquals(30, s.score(0), 1e-9);
|
||||||
|
Suspicion t = new Suspicion(cfg);
|
||||||
|
t.noter(Controle.TIMER, 1331, false, 0); // le timer a atteint 1331 en jeu
|
||||||
|
assertEquals(15, t.score(0), 1e-9);
|
||||||
|
assertEquals(Suspicion.Niveau.NORMAL, t.niveau(0), "un contrôle à faux positifs ne rend jamais suspect seul");
|
||||||
|
for (Controle c : List.of(Controle.ROTATION, Controle.ATTAQUE_IMPOSSIBLE, Controle.VEHICULE_VITESSE,
|
||||||
|
Controle.VEHICULE_VOL, Controle.TIMER)) {
|
||||||
|
t.noter(c, 999, false, 0);
|
||||||
|
}
|
||||||
|
// 5 contrôles faibles saturés = 75 : possible, mais seulement par accumulation (et par diversité, voir plus bas)
|
||||||
|
assertEquals(75, t.score(0), 1e-9);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void sommePlafonneeACent() {
|
||||||
|
for (Controle c : List.of(Controle.VOL, Controle.VITESSE, Controle.NO_FALL, Controle.PORTEE)) {
|
||||||
|
s.noter(c, 20, false, 0);
|
||||||
|
}
|
||||||
|
assertEquals(100, s.score(0), 1e-9);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void demiVieDeDixMinutes() {
|
||||||
|
s.noter(Controle.VITESSE, 20, false, 0);
|
||||||
|
assertEquals(50, s.score(0), 1e-9);
|
||||||
|
assertEquals(25, s.score(10 * MIN), 1e-6);
|
||||||
|
assertEquals(12.5, s.score(20 * MIN), 1e-6);
|
||||||
|
assertEquals(Suspicion.Niveau.A_SURVEILLER, s.niveau(10 * MIN));
|
||||||
|
assertEquals(Suspicion.Niveau.NORMAL, s.niveau(11 * MIN));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void ledecompteNeCompteQueLePicEtNonLeVlQuiRetombe() {
|
||||||
|
// Le VL retombe à 0 (setback ou 0,5/s) mais le pic reste dans le score jusqu'à décroissance.
|
||||||
|
s.noter(Controle.VOL, 20, true, 0);
|
||||||
|
s.noter(Controle.VOL, 1, false, 30_000); // VL reparti de zéro : le pic de 20 ne baisse pas
|
||||||
|
double apres = s.score(30_000);
|
||||||
|
assertTrue(apres > 45 && apres <= 50, "pic gardé, un peu décru : " + apres);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void diversiteTroisControlesAuPalierSetbackDonneSuspectFort() {
|
||||||
|
// Trois contrôles faibles, chacun à moitié : 3 x 7,5 = 22,5 (normal) sans la règle de diversité.
|
||||||
|
s.noter(Controle.TIMER, 10, true, 0);
|
||||||
|
s.noter(Controle.ROTATION, 10, true, 1 * MIN);
|
||||||
|
assertTrue(s.score(1 * MIN) < 25);
|
||||||
|
assertEquals(Suspicion.Niveau.NORMAL, s.niveau(1 * MIN));
|
||||||
|
s.noter(Controle.VEHICULE_VITESSE, 10, true, 2 * MIN);
|
||||||
|
assertTrue(s.score(2 * MIN) >= 75, "diversité : au moins suspect fort, score " + s.score(2 * MIN));
|
||||||
|
assertEquals(Suspicion.Niveau.SUSPECT_FORT, s.niveau(2 * MIN));
|
||||||
|
assertEquals(3, s.controlesDivers(2 * MIN));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void diversiteDeuxControlesNeSuffitPasEtLaFenetreExpire() {
|
||||||
|
s.noter(Controle.TIMER, 10, true, 0);
|
||||||
|
s.noter(Controle.ROTATION, 10, true, 1 * MIN);
|
||||||
|
assertFalse(s.score(1 * MIN) >= 75);
|
||||||
|
// Le troisième arrive après 10 minutes : le premier est sorti de la fenêtre.
|
||||||
|
s.noter(Controle.VEHICULE_VITESSE, 10, true, 10 * MIN + 1);
|
||||||
|
assertEquals(2, s.controlesDivers(10 * MIN + 1));
|
||||||
|
assertTrue(s.score(10 * MIN + 1) < 75);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void diversiteExigeLePalierSetback() {
|
||||||
|
s.noter(Controle.TIMER, 10, true, 0);
|
||||||
|
s.noter(Controle.ROTATION, 10, true, 0);
|
||||||
|
s.noter(Controle.VEHICULE_VITESSE, 4, false, 0); // seulement journal / alerte
|
||||||
|
assertEquals(2, s.controlesDivers(0));
|
||||||
|
assertTrue(s.score(0) < 75);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void diversiteCoupeeParLaConfiguration() {
|
||||||
|
cfg.suspicionDiversiteControles = 0;
|
||||||
|
s.noter(Controle.TIMER, 10, true, 0);
|
||||||
|
s.noter(Controle.ROTATION, 10, true, 0);
|
||||||
|
s.noter(Controle.VEHICULE_VITESSE, 10, true, 0);
|
||||||
|
assertTrue(s.score(0) < 75);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void transitionsUneSeuleFoisParPalierEtReArmement() {
|
||||||
|
s.noter(Controle.VOL, 10, false, 0); // 25
|
||||||
|
assertEquals(Suspicion.Niveau.A_SURVEILLER, s.prendreTransition());
|
||||||
|
assertNull(s.prendreTransition(), "consommée");
|
||||||
|
s.noter(Controle.VOL, 10.5, false, 1); // encore 26 : même palier
|
||||||
|
assertNull(s.prendreTransition());
|
||||||
|
s.noter(Controle.VITESSE, 10, false, 2); // 50
|
||||||
|
assertEquals(Suspicion.Niveau.SUSPECT, s.prendreTransition());
|
||||||
|
s.noter(Controle.NO_FALL, 10, false, 3); // 75
|
||||||
|
assertEquals(Suspicion.Niveau.SUSPECT_FORT, s.prendreTransition());
|
||||||
|
s.noter(Controle.NO_FALL, 20, false, 4);
|
||||||
|
assertNull(s.prendreTransition(), "déjà notifié");
|
||||||
|
|
||||||
|
// Longtemps après, le score est retombé sous 25 : le palier peut de nouveau être franchi.
|
||||||
|
s.noter(Controle.TIMER, 1, false, 60 * MIN);
|
||||||
|
s.prendreTransition();
|
||||||
|
s.noter(Controle.VOL, 20, false, 60 * MIN + 1);
|
||||||
|
assertEquals(Suspicion.Niveau.SUSPECT, s.prendreTransition());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void passageDirectAuFortParDiversiteNEmetQueLeFort() {
|
||||||
|
s.noter(Controle.TIMER, 10, true, 0);
|
||||||
|
s.noter(Controle.ROTATION, 10, true, 0);
|
||||||
|
s.noter(Controle.VEHICULE_VITESSE, 10, true, 0);
|
||||||
|
assertEquals(Suspicion.Niveau.SUSPECT_FORT, s.prendreTransition());
|
||||||
|
assertNull(s.prendreTransition());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void desactiveParLaConfiguration() {
|
||||||
|
cfg.suspicionActive = false;
|
||||||
|
s.noter(Controle.VOL, 20, true, 0);
|
||||||
|
assertEquals(0, s.score(0));
|
||||||
|
assertNull(s.prendreTransition());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void horlogeQuiRecule_PasDeScoreNegatifNiDeRemontee() {
|
||||||
|
s.noter(Controle.VOL, 20, false, 10 * MIN);
|
||||||
|
double avant = s.score(10 * MIN);
|
||||||
|
s.noter(Controle.VITESSE, 0, false, 5 * MIN); // horloge en arrière : ignorée
|
||||||
|
assertEquals(avant, s.score(10 * MIN), 1e-9);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Dans le moteur : contrôles en OBSERVE inclus, aucune sanction, historique ---
|
||||||
|
|
||||||
|
private static void tapesRegulieres(Moteur m, UUID id, int n, long[] t, java.util.List<Verdict> sortie) {
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
t[0] += 50;
|
||||||
|
sortie.addAll(m.attaque(id, t[0], EtatJoueur.normal(), -1, 1, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void controlesEnObserveComptentMaisNeSanctionnentPas() {
|
||||||
|
GardeConfig c = new GardeConfig();
|
||||||
|
c.mode(Controle.REGULARITE, Mode.OBSERVE);
|
||||||
|
Moteur m = new Moteur(c);
|
||||||
|
long[] horloge = {0};
|
||||||
|
m.horloge(() -> horloge[0]);
|
||||||
|
UUID id = UUID.randomUUID();
|
||||||
|
java.util.List<Verdict> vs = new java.util.ArrayList<>();
|
||||||
|
tapesRegulieres(m, id, 60, horloge, vs);
|
||||||
|
assertTrue(vs.stream().allMatch(v -> v.applicable().ordinal() <= Sanction.ALERTE.ordinal()),
|
||||||
|
"OBSERVE ne dépasse jamais l'alerte");
|
||||||
|
assertEquals(50, m.scoreSuspicion(id), 1e-6, "la régularité en OBSERVE a atteint son plafond de 50");
|
||||||
|
Moteur.AlerteSuspicion a = m.alerteSuspicion(id, 1_000_000L);
|
||||||
|
assertNotNull(a);
|
||||||
|
assertEquals(Suspicion.Niveau.SUSPECT, a.niveau());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void alerteEnregistreLIncidentDansLHistoriqueSeulementDesSuspect() {
|
||||||
|
GardeConfig c = new GardeConfig();
|
||||||
|
Moteur m = new Moteur(c);
|
||||||
|
long[] horloge = {0};
|
||||||
|
m.horloge(() -> horloge[0]);
|
||||||
|
UUID id = UUID.randomUUID();
|
||||||
|
// Cadence (moyen, 30 max) : reste « à surveiller » ; pas d'incident dans l'historique.
|
||||||
|
m.suivi(id).suspicion.noter(Controle.CADENCE, 20, false, 0);
|
||||||
|
Moteur.AlerteSuspicion a = m.alerteSuspicion(id, 5_000L);
|
||||||
|
assertEquals(Suspicion.Niveau.A_SURVEILLER, a.niveau());
|
||||||
|
assertEquals(0, a.incidents());
|
||||||
|
m.suivi(id).suspicion.noter(Controle.REGULARITE, 8, false, 0);
|
||||||
|
a = m.alerteSuspicion(id, 6_000L);
|
||||||
|
assertEquals(Suspicion.Niveau.SUSPECT, a.niveau());
|
||||||
|
assertEquals(1, a.incidents());
|
||||||
|
assertTrue(a.controles().contains("regularite:20"), a.controles());
|
||||||
|
assertNull(m.alerteSuspicion(id, 7_000L));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void scoreRepartDeZeroApresReconnexion() {
|
||||||
|
Moteur m = new Moteur(new GardeConfig());
|
||||||
|
m.horloge(() -> 0L);
|
||||||
|
UUID id = UUID.randomUUID();
|
||||||
|
m.suivi(id).suspicion.noter(Controle.VOL, 20, false, 0);
|
||||||
|
assertTrue(m.scoreSuspicion(id) > 0);
|
||||||
|
m.retirer(id);
|
||||||
|
assertEquals(0, m.scoreSuspicion(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Historique persistant ---
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void historiquePersisteEtOublieLesVieuxIncidents(@TempDir Path dir) throws IOException {
|
||||||
|
Path f = dir.resolve("sous-dossier").resolve("incidents.csv");
|
||||||
|
long jour = 86_400_000L;
|
||||||
|
long maintenant = 100 * jour;
|
||||||
|
UUID a = UUID.randomUUID();
|
||||||
|
UUID b = UUID.randomUUID();
|
||||||
|
HistoriqueSuspicion h = new HistoriqueSuspicion();
|
||||||
|
h.ouvrir(f, maintenant, 7);
|
||||||
|
h.enregistrer(a, maintenant - 8 * jour, Suspicion.Niveau.SUSPECT, 55, "vol:50");
|
||||||
|
h.enregistrer(a, maintenant - 3 * jour, Suspicion.Niveau.SUSPECT_FORT, 80, "vol:50;vitesse:30"); // ';' neutralisé
|
||||||
|
h.enregistrer(b, maintenant - 1 * jour, Suspicion.Niveau.SUSPECT, 50, "regularite:50");
|
||||||
|
assertEquals(1, h.incidents(a, maintenant, 7), "celui de 8 jours est hors fenêtre même en mémoire");
|
||||||
|
|
||||||
|
// Redémarrage : relecture du fichier, le vieil incident est écarté et le fichier réécrit compact.
|
||||||
|
Files.writeString(f, "ligne illisible\n", StandardCharsets.UTF_8, java.nio.file.StandardOpenOption.APPEND);
|
||||||
|
HistoriqueSuspicion h2 = new HistoriqueSuspicion();
|
||||||
|
h2.ouvrir(f, maintenant, 7);
|
||||||
|
assertEquals(1, h2.incidents(a, maintenant, 7));
|
||||||
|
assertEquals(1, h2.incidents(b, maintenant, 7));
|
||||||
|
assertEquals(0, h2.incidents(UUID.randomUUID(), maintenant, 7));
|
||||||
|
assertEquals(2, Files.readAllLines(f).size(), "fichier compact : plus de vieille ligne ni de ligne illisible");
|
||||||
|
// Plus tard, l'incident de a sort aussi de la fenêtre.
|
||||||
|
assertEquals(0, h2.incidents(a, maintenant + 5 * jour, 7));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void historiqueSansFichierResteEnMemoire() {
|
||||||
|
HistoriqueSuspicion h = new HistoriqueSuspicion();
|
||||||
|
UUID a = UUID.randomUUID();
|
||||||
|
h.enregistrer(a, 1000, Suspicion.Niveau.SUSPECT, 50, "x");
|
||||||
|
assertEquals(1, h.incidents(a, 2000, 7));
|
||||||
|
}
|
||||||
|
}
|
||||||
Référencer dans un nouveau ticket
Bloquer un utilisateur