GastinelGarde 0.4.0 : score de suspicion, flottement du vol, motif de sanction corrige
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Cette révision appartient à :
1 Parent
288087080f
révision
c7b130ec1c
14 fichiers modifiés
+985
-2
Aucun fichier ne correspond à votre recherche
@@ -138,9 +138,23 @@ final class Cablage {
|
||||
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). */
|
||||
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) {
|
||||
// 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;
|
||||
|
||||
@@ -143,6 +143,13 @@ public final class Garde {
|
||||
Files.createDirectories(journal.getParent());
|
||||
traces = new TraceFichier(jeu.resolve("gastinelgarde-traces"), GardeSpec.tracesJours(), GardeSpec.tracesTailleOctets());
|
||||
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) {
|
||||
GastinelGarde.LOGGER.error("[GastinelGarde] Impossible d'ouvrir le dossier de traces", e);
|
||||
traces = null;
|
||||
@@ -524,9 +531,31 @@ public final class Garde {
|
||||
}
|
||||
if (v.notifier()) alerterOps(p, v);
|
||||
}
|
||||
reagirSuspicion(p);
|
||||
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) {
|
||||
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()))
|
||||
|
||||
@@ -91,6 +91,8 @@ public final class GardeCommands {
|
||||
sb.append("\n ").append(k.id()).append(" VL=")
|
||||
.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)");
|
||||
ok(ctx, sb.toString());
|
||||
return 1;
|
||||
|
||||
@@ -51,6 +51,10 @@ public final class GardeSpec {
|
||||
private static final ModConfigSpec.IntValue SERIE_PING_MAX;
|
||||
private static final ModConfigSpec.IntValue SERIE_PING_MARGE;
|
||||
private static final ModConfigSpec.IntValue TIMER_SOLDE_MAX;
|
||||
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 VITESSE_MOYENNE;
|
||||
private static final ModConfigSpec.BooleanValue ELYTRES_STRICTE;
|
||||
@@ -155,7 +159,34 @@ public final class GardeSpec {
|
||||
.defineInRange("timerSoldeMax", 0, 0, 1000);
|
||||
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.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.",
|
||||
"Valeurs de départ généreuses, à resserrer avec les traces réelles.")
|
||||
.defineInRange("excesVitesseBlocs", 1.5, 0.1, 100.0);
|
||||
@@ -280,6 +311,18 @@ public final class GardeSpec {
|
||||
c.seriePingMaxMs = SERIE_PING_MAX.get();
|
||||
c.seriePingMargeMs = SERIE_PING_MARGE.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.volFenetreGlissante = VOL_FENETRE_GLISSANTE.get();
|
||||
c.vitesseMoyenne = VITESSE_MOYENNE.get();
|
||||
c.elytresExemptionStricte = ELYTRES_STRICTE.get();
|
||||
|
||||
@@ -39,6 +39,15 @@ public enum Controle {
|
||||
|| 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 -> 0;
|
||||
case COUPS_HORS_BOITE, KILLAURA_ANGLE, KILLAURA_CIBLES, CADENCE -> 1;
|
||||
case TIMER, ROTATION, ATTAQUE_IMPOSSIBLE, VEHICULE_VITESSE, VEHICULE_VOL -> 2;
|
||||
};
|
||||
}
|
||||
|
||||
public static Controle parse(String texte) {
|
||||
if (texte == null) return null;
|
||||
for (Controle c : values()) {
|
||||
|
||||
@@ -26,6 +26,26 @@ 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). */
|
||||
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;
|
||||
|
||||
// --- Killaura ---
|
||||
/** Angle maximal entre le regard et la silhouette de la cible, en degrés. */
|
||||
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). */
|
||||
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) {
|
||||
this.cfg = cfg;
|
||||
}
|
||||
@@ -33,7 +72,7 @@ public final class Moteur {
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -369,6 +408,7 @@ public final class Moteur {
|
||||
s.vol.vider(); // le paquet qui suit la grâce sert de référence
|
||||
} else if (vol) {
|
||||
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);
|
||||
ajouter(verdicts, s, Controle.VOL, pts, nowMs, ex, String.format(Locale.ROOT, "dy=%.3f en l'air", m.dy()));
|
||||
}
|
||||
@@ -493,6 +533,7 @@ public final class Moteur {
|
||||
palier = Sanction.min(Sanction.EXPULSION, cfg.sanctionMax);
|
||||
}
|
||||
Sanction applicable = Paliers.applicable(palier, mode);
|
||||
s.suspicion.noter(c, vl, palier.ordinal() >= Sanction.SETBACK.ordinal(), horloge.getAsLong());
|
||||
boolean notifier = applicable.ordinal() >= Sanction.ALERTE.ordinal()
|
||||
&& s.autoriserAlerte(c, nowMs, DELAI_ALERTE_MS);
|
||||
sortie.add(new Verdict(c, mode, points, vl, palier, applicable, notifier, details, ex.raisons()));
|
||||
|
||||
@@ -53,8 +53,16 @@ public final class Suivi {
|
||||
|
||||
private final Map<Controle, Long> derniereAlerte = new EnumMap<>(Controle.class);
|
||||
|
||||
/** Score de suspicion (0.4.0). */
|
||||
public final Suspicion suspicion;
|
||||
|
||||
public Suivi(double decroissanceParSeconde) {
|
||||
this(decroissanceParSeconde, new GardeConfig());
|
||||
}
|
||||
|
||||
public Suivi(double decroissanceParSeconde, GardeConfig cfg) {
|
||||
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) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -106,6 +106,8 @@ public final class VolVertical {
|
||||
}
|
||||
}
|
||||
|
||||
points = Math.max(points, flottement(exempt || e.milieuSpecial() || !enAir, dy, n));
|
||||
|
||||
derniereVitesse = vitesseFin;
|
||||
aVitesse = true;
|
||||
etaitEnAir = enAir;
|
||||
@@ -138,6 +140,29 @@ public final class VolVertical {
|
||||
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 || neutre || ticks < 1 || ticks > TICKS_MAX || dy / ticks < DY_FLOTTANT) {
|
||||
flottementTicks = 0;
|
||||
return 0;
|
||||
}
|
||||
flottementTicks += ticks;
|
||||
if (flottementTicks <= flottementMax) return 0;
|
||||
return 1.5;
|
||||
}
|
||||
|
||||
private void viderFenetre() {
|
||||
java.util.Arrays.fill(fenetre, false);
|
||||
fenetreIndex = 0;
|
||||
@@ -152,6 +177,7 @@ public final class VolVertical {
|
||||
etaitEnAir = false;
|
||||
anormauxConsecutifs = 0;
|
||||
avance = 0;
|
||||
flottementTicks = 0;
|
||||
viderFenetre();
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
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