LoadAllPromotions builds one PromotionClass per promotion CLASS rune (22, 2504-2526 without 2522) and caches it, then runs the DB loader, which skips cached ids, so only the CSR/admin rows 2901-2911 still come from static_rune_promotion (decision: DB fallback). The world server calls it in place of GET_ALL_PROMOTIONS; the login server now preloads promotions too, so character load there gets the same cached objects. The SQL loader stays until task 2.11. Value changes: Templar 2516 manaMod 14 -> 15 (decision: JSON, D2). description NULL -> rune_dsc blurb (unread). All other fields unchanged; final parity before the switch (scripts/p22.py): 22 promotion rows, 0 differences in name, token, health, stamina and the 163 allowed rune tokens. The static_rune_promotion comparator is removed; it would only compare the JSON with itself now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
3.1 KiB
Java
85 lines
3.1 KiB
Java
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
|
// Magicbane Emulator Project © 2013 - 2026
|
|
// https://www.magicbane.com
|
|
|
|
package engine.parsers.cache;
|
|
|
|
import engine.gameManager.ConfigManager;
|
|
import org.pmw.tinylog.Logger;
|
|
|
|
import java.util.LinkedHashMap;
|
|
import java.util.Objects;
|
|
import java.util.function.Consumer;
|
|
|
|
// Dev-only check that compares DB-built objects with the cache JSON before a loader is switched.
|
|
// Enabled by the optional env var MB_PARITY_CHECK; not in the ConfigManager enum, which requires every entry.
|
|
|
|
public class ParityCheck {
|
|
|
|
private static final String FLAG_NAME = "MB_PARITY_CHECK";
|
|
private static final LinkedHashMap<String, Consumer<ParityCheck>> comparators = new LinkedHashMap<>();
|
|
|
|
private final String table;
|
|
private int comparedCount = 0;
|
|
private int differenceCount = 0;
|
|
private int missingCount = 0;
|
|
|
|
private ParityCheck(String table) {
|
|
this.table = table;
|
|
}
|
|
|
|
public static boolean isEnabled() {
|
|
return ConfigManager.configMap.getOrDefault(FLAG_NAME, "false").equalsIgnoreCase("true");
|
|
}
|
|
|
|
public static void register(String table, Consumer<ParityCheck> comparator) {
|
|
comparators.put(table, comparator);
|
|
}
|
|
|
|
public static void run() {
|
|
|
|
ParityCheck check;
|
|
|
|
for (String table : comparators.keySet()) {
|
|
check = new ParityCheck(table);
|
|
|
|
try {
|
|
comparators.get(table).accept(check);
|
|
} catch (Exception e) {
|
|
Logger.error("Parity: " + table + ": comparator failed: " + e);
|
|
}
|
|
|
|
Logger.info("Parity: " + table + ": " + check.comparedCount + " compared, "
|
|
+ check.differenceCount + " differences, " + check.missingCount + " missing in json");
|
|
}
|
|
}
|
|
|
|
// Returns false when the row has no JSON counterpart, so the comparator can skip its fields.
|
|
|
|
public boolean compareRow(int id, Object jsonObject) {
|
|
|
|
comparedCount++;
|
|
|
|
if (jsonObject == null) {
|
|
missingCount++;
|
|
Logger.warn("Parity: " + table + "/" + id + ": missing in json");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public void compareField(int id, String field, Object dbValue, Object jsonValue) {
|
|
|
|
if (Objects.equals(dbValue, jsonValue))
|
|
return;
|
|
|
|
differenceCount++;
|
|
Logger.warn("Parity: " + table + "/" + id + "/" + field + ": db=" + dbValue + " json=" + jsonValue);
|
|
}
|
|
}
|