Premier commit
Cette révision appartient à :
révision
43ac041278
6 fichiers modifiés
+705
Aucun fichier ne correspond à votre recherche
@@ -0,0 +1,118 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Correctif dédié : dans la liste d'AMIS de totoche10, e65f2350-… (« gabybou201 » sans guillemet)
|
||||
devient 128c0f10-… (« gabybou201" », le compte réellement utilisé). RIEN d'autre n'est modifié :
|
||||
ni les claims (owner), ni les autres fichiers, ni les amis des autres joueurs.
|
||||
|
||||
Python 3 stdlib. Réutilise le lecteur/écrivain NBT de migrer-uuid.py (même dossier).
|
||||
|
||||
--dossier DIR racine des données (contient neW512/data/gastinelclaims.dat)
|
||||
--appliquer écrit (défaut : À BLANC). Refuse si le conteneur minecraft-neoforge tourne,
|
||||
sauf dossier marqué COPIE-MIGRATION.
|
||||
--retour restaure gastinelclaims.dat depuis gastinelclaims.dat.avant-pseudos
|
||||
--inverse applique le mappage inverse (sans toucher à la sauvegarde existante)
|
||||
Idempotent : relancé après application, il ne trouve plus rien à faire.
|
||||
Sauvegarde : <dat>.avant-pseudos (créée une seule fois, jamais écrasée).
|
||||
"""
|
||||
import argparse, importlib.util, os, shutil, subprocess, sys
|
||||
|
||||
PROP = "e1769fd1-91f1-377b-b2ac-999a4a7c9c9e" # totoche10 (hors-ligne)
|
||||
ANCIEN = "e65f2350-d100-3a51-ae80-50fbcce624c0" # OfflinePlayer:gabybou201
|
||||
NOUVEAU = "128c0f10-9643-37ff-941d-afa49cdb30ec" # OfflinePlayer:gabybou201"
|
||||
CONTENEUR = "minecraft-neoforge"
|
||||
|
||||
|
||||
def charger_nbt():
|
||||
ici = os.path.dirname(os.path.abspath(__file__))
|
||||
spec = importlib.util.spec_from_file_location("migrer_uuid", os.path.join(ici, "migrer-uuid.py"))
|
||||
m = importlib.util.module_from_spec(spec); spec.loader.exec_module(m)
|
||||
return m
|
||||
|
||||
|
||||
def serveur_en_ligne():
|
||||
try:
|
||||
r = subprocess.run(["docker", "ps", "--filter", "name=^%s$" % CONTENEUR, "--format", "{{.Names}}"],
|
||||
capture_output=True, text=True, timeout=15)
|
||||
if r.returncode != 0:
|
||||
return True
|
||||
return CONTENEUR in r.stdout
|
||||
except Exception:
|
||||
return True
|
||||
|
||||
|
||||
def trouver_listes_amis(tag, out):
|
||||
"""Toutes les entrées de listes nommées 'friends' (compound avec owner + friends)."""
|
||||
if tag.t == 10:
|
||||
for k, s in tag.v.items():
|
||||
if k == "friends" and s.t == 9 and s.v[0] == 10:
|
||||
for ent in s.v[1]:
|
||||
out.append(ent)
|
||||
trouver_listes_amis(s, out)
|
||||
elif tag.t == 9:
|
||||
for s in tag.v[1]:
|
||||
trouver_listes_amis(s, out)
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
ap.add_argument("--dossier", required=True)
|
||||
ap.add_argument("--appliquer", action="store_true")
|
||||
ap.add_argument("--retour", action="store_true")
|
||||
ap.add_argument("--inverse", action="store_true",
|
||||
help="mappage inverse (128c0f10 -> e65f2350) : retour logique si le .dat a changé depuis")
|
||||
a = ap.parse_args()
|
||||
global ANCIEN, NOUVEAU
|
||||
if a.inverse:
|
||||
ANCIEN, NOUVEAU = NOUVEAU, ANCIEN
|
||||
D = os.path.abspath(a.dossier)
|
||||
dat = os.path.join(D, "neW512", "data", "gastinelclaims.dat")
|
||||
bak = dat + ".avant-pseudos"
|
||||
copie = os.path.exists(os.path.join(D, "COPIE-MIGRATION"))
|
||||
if not os.path.exists(dat):
|
||||
print("ERREUR : %s absent" % dat); return 2
|
||||
if (a.appliquer or a.retour) and serveur_en_ligne() and not copie:
|
||||
print("REFUS : Minecraft tourne (ou docker ne répond pas). Rien n'est modifié."); return 3
|
||||
|
||||
if a.retour:
|
||||
if not os.path.exists(bak):
|
||||
print("Rien à restaurer (%s absent)." % bak); return 0
|
||||
shutil.copy2(bak, dat); print("Restauré :", dat); return 0
|
||||
|
||||
m = charger_nbt()
|
||||
gz, nom, rac = m.lire_nbt(dat)
|
||||
ents = []; trouver_listes_amis(rac, ents)
|
||||
si, di, pi = m.u2ints(ANCIEN), m.u2ints(NOUVEAU), m.u2ints(PROP)
|
||||
avant_claims = None
|
||||
modifs = 0
|
||||
for ent in ents:
|
||||
d = ent.v
|
||||
if "owner" not in d or d["owner"].t != 11 or d["owner"].v != pi:
|
||||
continue
|
||||
lst = d["friends"]; et, items = lst.v
|
||||
valeurs = [it.v for it in items]
|
||||
a_ancien = si in valeurs
|
||||
a_nouveau = di in valeurs
|
||||
print("amis de totoche10 : ancien=%s nouveau=%s (%d amis)" % (a_ancien, a_nouveau, len(items)))
|
||||
if not a_ancien:
|
||||
continue
|
||||
nouveaux = []
|
||||
for it in items:
|
||||
if it.v == si:
|
||||
if a_nouveau or any(n.v == di for n in nouveaux):
|
||||
continue # le bon est déjà là : on retire seulement l'ancien
|
||||
it.v = list(di)
|
||||
nouveaux.append(it)
|
||||
lst.v = (et, nouveaux); modifs += 1
|
||||
if modifs == 0:
|
||||
print("RIEN À FAIRE (déjà corrigé ou ancien UUID absent)."); return 0
|
||||
if not a.appliquer:
|
||||
print("À BLANC : 1 liste d'amis serait corrigée (%s -> %s). Rien écrit." % (ANCIEN, NOUVEAU)); return 0
|
||||
if not os.path.exists(bak):
|
||||
shutil.copy2(dat, bak)
|
||||
m.ecrire_nbt(dat, gz, nom, rac)
|
||||
print("APPLIQUÉ : %s -> %s dans les amis de totoche10. Sauvegarde : %s" % (ANCIEN, NOUVEAU, bak))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur