commit 13d1bb5574021d22c7e7a2a7da5b413885e6233b Author: Théo Gastinel <264859180+gastinelt@users.noreply.github.com> Date: Sun Oct 11 01:53:42 2026 +0200 Premier commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0620b0b --- /dev/null +++ b/.gitignore @@ -0,0 +1,72 @@ +/GastinelAuth/ +/GastinelClaims/ +/GastinelMindPNJ/ +/GastinelTpa/ +/GastinelVision/ +/GastinelWind/ + +# --- double-push : exclusions generiques (secrets, builds, binaires, gros fichiers) --- +target/ +node_modules/ +build/ +build-*/ +dist/ +out/ +.gradle/ +.idea/ +venv/ +.venv/ +env/ +__pycache__/ +*.pyc +.cache/ +.next/ +.env +.env.* +!.env.example +accounts.json +Clee.API/ +*.pem +*.key +*.p12 +*.pfx +*.jks +*.keystore +keystore.properties +id_rsa* +id_ed25519* +*.kdbx +*.odt +*.sqlite +*.sqlite3 +*.db +*.log +*.exe +*.dll +*.msi +*.jar +*.zip +*.7z +*.rar +*.tar +*.tar.gz +*.tgz +*.gguf +*.safetensors +*.onnx +*.pt +*.pth +*.bin +*.iso +*.gws +*.apk +*.aab +*.so +*.o +*.a +*.lib +*.pdb +*.mp4 +*.mkv +*.wav +*.flac diff --git a/deployer-spawn-rtp-guide.sh b/deployer-spawn-rtp-guide.sh new file mode 100644 index 0000000..027ae30 --- /dev/null +++ b/deployer-spawn-rtp-guide.sh @@ -0,0 +1,154 @@ +#!/bin/bash +# Déploie GastinelTpa 1.1.0 (/spawn, /rtp), GastinelMindPNJ 1.1.0 (/guide), GastinelClaims 1.1.0 (zone de spawn protégée) +# sur le serveur Minecraft NeoForge de cornafserver. À lancer SUR cornafserver. +# +# bash deployer-spawn-rtp-guide.sh # déploie (jars attendus dans ~/staging/deploiement-spawn-rtp-guide/) +# bash deployer-spawn-rtp-guide.sh --retour # remet les anciens jars (*.avant-spawn-rtp-guide) et redémarre +# +# Ne touche qu'au conteneur minecraft-neoforge. GastinelAuth et GastinelWind ne sont pas modifiés. +set -euo pipefail + +STACK="$HOME/server-infra/stacks/minecraft-neoforge" +DATA="$STACK/data" +MODS="$DATA/mods" +SRC="$HOME/staging/deploiement-spawn-rtp-guide" +SUFFIXE="avant-spawn-rtp-guide" +CONTENEUR="minecraft-neoforge" +NOUVEAUX=(gastineltpa-neoforge-1.21.1-1.1.0.jar gastinelmind-neoforge-1.21.1-1.1.0.jar gastinelclaims-neoforge-1.21.1-1.1.0.jar) +ANCIENS=(gastineltpa-neoforge-1.21.1-1.0.0.jar gastinelmind-neoforge-1.21.1-1.0.0.jar gastinelclaims-neoforge-1.21.1-1.0.0.jar) +SAUV="$HOME/staging/sauvegardes-$SUFFIXE" + +log() { echo "[$(date '+%F %T')] $*"; } +rcon() { docker exec "$CONTENEUR" rcon-cli "$@" 2>/dev/null || true; } + +joueurs_en_ligne() { + # "There are N of a max of M players online: ..." + rcon list | sed -n 's/.*There are \([0-9]*\) of.*/\1/p' | head -1 +} + +prevenir_et_sauver() { + local n; n=$(joueurs_en_ligne); n=${n:-0} + log "Joueurs connectés : $n" + rcon list + if [ "$n" -gt 0 ]; then + rcon say "Redémarrage du serveur dans 60 s (nouvelles commandes /spawn, /rtp, /guide). Durée : environ 2 min." + sleep 30; rcon say "Redémarrage dans 30 s." + sleep 20; rcon say "Redémarrage dans 10 s. Sauvegarde du monde…" + sleep 10 + fi + rcon save-all flush + sleep 5 +} + +verifier_pas_de_generation() { + # Tâche 75 / génération Bonsai / Chunky : ne pas redémarrer pendant une prégénération. + if docker logs --since 10m "$CONTENEUR" 2>&1 | grep -qiE "chunky.*(task|tâche).*(running|progress)|\[Chunky\].*[0-9]+\.[0-9]+%"; then + log "ERREUR : une génération Chunky semble en cours (log des 10 dernières minutes). Abandon." + exit 2 + fi + # (le lanceur « bash -c sleep N; exec ./session-generation.sh … tache75.sh » qui attend son heure ne compte pas) + local actifs + actifs=$(pgrep -aif "bonsai|tache.?75" | grep -v -e pgrep -e "sleep [0-9]" || true) + if [ -n "$actifs" ]; then + log "ERREUR : un processus Bonsai / tâche 75 tourne. Abandon." + echo "$actifs" | cut -c1-200 + exit 2 + fi +} + +redemarrer_et_attendre() { + local debut=$SECONDS + log "Redémarrage du conteneur $CONTENEUR" + docker restart "$CONTENEUR" >/dev/null + for _ in $(seq 1 120); do + sleep 5 + if docker logs --since "$1" "$CONTENEUR" 2>&1 | grep -q 'Done ('; then + log "Serveur démarré en $((SECONDS - debut)) s." + return 0 + fi + if ! docker ps --format '{{.Names}}' | grep -qx "$CONTENEUR"; then + log "Conteneur arrêté pendant le démarrage." + return 1 + fi + done + log "Pas de 'Done' après 10 min." + return 1 +} + +verifier_log() { + local depuis="$1" ok=0 l + l=$(docker logs --since "$depuis" "$CONTENEUR" 2>&1) + echo "$l" | grep -q 'Done (' || { log "KO : pas de démarrage complet"; ok=1; } + echo "$l" | grep -qiE 'Mixin apply.*failed|InvalidInjectionException|Crash report|Failed to load mod' && { log "KO : erreur de mod/mixin dans le log"; ok=1; } + echo "$l" | grep -q '\[GastinelTpa\] Téléportations chargées' || { log "KO : GastinelTpa 1.1.0 non chargé"; ok=1; } + echo "$l" | grep -q 'Zone protégée active : spawn' || { log "KO : zone protégée « spawn » non chargée"; ok=1; } + echo "$l" | grep -q 'dans la zone protégée « spawn »' || log "ATTENTION : le spawn du monde n'est pas dans la zone « spawn »" + echo "$l" | grep -q '\[GastinelAuth\] Mod initialisé' || { log "KO : GastinelAuth non initialisé"; ok=1; } + # Le serveur vocal démarre un peu après « Done » : on lui laisse 30 s. + for _ in 1 2 3 4 5 6; do + docker logs --since "$depuis" "$CONTENEUR" 2>&1 | grep -q 'Voice chat server started at port 24454' && break + sleep 5 + done + docker logs --since "$depuis" "$CONTENEUR" 2>&1 | grep -q 'Voice chat server started at port 24454' \ + || { log "KO : chat vocal (24454/UDP) non démarré"; ok=1; } + # Commande enregistrée = pas de « Unknown or incomplete command » (depuis la console, /spawn et /guide + # répondent « A player is required… », /rtp spawn répond par le refus « réservé à la plaque de pression »). + for c in "spawn" "rtp spawn" "guide" "zoneprotegee liste"; do + if rcon "$c" | grep -q 'Unknown or incomplete command'; then log "KO : commande /$c absente"; ok=1 + else log "Commande /$c : présente"; fi + done + return $ok +} + +retour_arriere() { + log "RETOUR ARRIÈRE : remise des anciens jars" + for i in 0 1 2; do + rm -f "$MODS/${NOUVEAUX[$i]}" + if [ -f "$MODS/${ANCIENS[$i]}.$SUFFIXE" ]; then + mv -f "$MODS/${ANCIENS[$i]}.$SUFFIXE" "$MODS/${ANCIENS[$i]}" + fi + done + local t; t=$(date -u +%Y-%m-%dT%H:%M:%SZ) + redemarrer_et_attendre "$t" || log "ERREUR : le serveur ne redémarre pas après retour arrière, intervention manuelle nécessaire." + rcon list +} + +if [ "${1:-}" = "--retour" ]; then + prevenir_et_sauver + retour_arriere + exit 0 +fi + +# --- Déploiement --- +for j in "${NOUVEAUX[@]}"; do [ -f "$SRC/$j" ] || { log "Jar manquant : $SRC/$j"; exit 1; }; done +for j in "${ANCIENS[@]}"; do [ -f "$MODS/$j" ] || { log "Ancien jar absent : $MODS/$j (déjà déployé ?)"; exit 1; }; done +verifier_pas_de_generation + +mkdir -p "$SAUV" +cp -a "$DATA/config" "$SAUV/config-$(date +%Y%m%d-%H%M%S)" +cp -a "$DATA/neW512/serverconfig" "$SAUV/serverconfig-$(date +%Y%m%d-%H%M%S)" +log "Configs sauvegardées dans $SAUV" + +# Fichiers de config des nouvelles fonctions (seulement s'ils n'existent pas déjà) +mkdir -p "$DATA/config/gastineltpa" +[ -f "$DATA/config/gastineltpa/beaux-spots.json" ] || cp "$SRC/beaux-spots.json" "$DATA/config/gastineltpa/beaux-spots.json" + +prevenir_et_sauver +for i in 0 1 2; do + mv -f "$MODS/${ANCIENS[$i]}" "$MODS/${ANCIENS[$i]}.$SUFFIXE" + cp "$SRC/${NOUVEAUX[$i]}" "$MODS/${NOUVEAUX[$i]}" +done +log "Jars remplacés (anciens : *.$SUFFIXE)" + +DEBUT=$(date -u +%Y-%m-%dT%H:%M:%SZ) +ARRET=$(date '+%T') +if redemarrer_et_attendre "$DEBUT" && verifier_log "$DEBUT"; then + log "DÉPLOIEMENT OK (arrêt à $ARRET, de nouveau disponible à $(date '+%T'))." + rcon "zoneprotegee liste" + rcon list +else + log "DÉPLOIEMENT KO : retour arrière automatique." + docker logs --since "$DEBUT" "$CONTENEUR" 2>&1 | grep -iE 'error|exception' | head -30 || true + retour_arriere + exit 1 +fi diff --git a/deployer-tpa-1-1-1.sh b/deployer-tpa-1-1-1.sh new file mode 100644 index 0000000..ca65a5b --- /dev/null +++ b/deployer-tpa-1-1-1.sh @@ -0,0 +1,124 @@ +#!/bin/bash +# Déploie GastinelTpa 1.1.1 (recharge 1 s silencieuse, message d'attente, délai TPA caché). À lancer SUR cornafserver. +# bash deployer-tpa-1-1-1.sh # déploie (jar attendu dans ~/staging/deploiement-tpa-1-1-1/) +# bash deployer-tpa-1-1-1.sh --retour # remet le jar 1.1.0 et l'ancienne config, puis redémarre +# Ne redémarre que minecraft-neoforge. Ne touche à aucun autre mod. +set -euo pipefail + +DATA="$HOME/server-infra/stacks/minecraft-neoforge/data" +MODS="$DATA/mods" +CFG="$DATA/config/gastineltpa-server.toml" +SRC="$HOME/staging/deploiement-tpa-1-1-1" +SUFFIXE="avant-tpa-1-1-1" +CONTENEUR="minecraft-neoforge" +NOUVEAU="gastineltpa-neoforge-1.21.1-1.1.1.jar" +ANCIEN="gastineltpa-neoforge-1.21.1-1.1.0.jar" +SAUV="$HOME/staging/sauvegardes-$SUFFIXE" + +log() { echo "[$(date '+%F %T')] $*"; } +rcon() { docker exec "$CONTENEUR" rcon-cli "$@" 2>/dev/null || true; } + +prevenir_et_sauver() { + local n; n=$(rcon list | sed -n 's/.*There are \([0-9]*\) of.*/\1/p' | head -1); n=${n:-0} + log "Joueurs connectés : $n"; rcon list + if [ "$n" -gt 0 ]; then + rcon say "Redémarrage du serveur dans 60 s (mise à jour /spawn, /rtp, /tpa). Durée : environ 2 min." + sleep 30; rcon say "Redémarrage dans 30 s." + sleep 20; rcon say "Redémarrage dans 10 s. Sauvegarde du monde…" + sleep 10 + fi + rcon save-all flush + sleep 5 +} + +verifier_pas_de_generation() { + if docker logs --since 10m "$CONTENEUR" 2>&1 | grep -qiE "chunky.*(task|tâche).*(running|progress)|\[Chunky\].*[0-9]+\.[0-9]+%"; then + log "ERREUR : génération Chunky en cours. Abandon."; exit 2 + fi + local actifs + actifs=$(pgrep -aif "bonsai|tache.?75" | grep -v -e pgrep -e "sleep [0-9]" || true) + if [ -n "$actifs" ]; then log "ERREUR : processus Bonsai / tâche 75 en cours. Abandon."; exit 2; fi +} + +redemarrer_et_attendre() { + local debut=$SECONDS + log "Redémarrage du conteneur $CONTENEUR" + docker restart "$CONTENEUR" >/dev/null + for _ in $(seq 1 120); do + sleep 5 + if docker logs --since "$1" "$CONTENEUR" 2>&1 | grep -q 'Done ('; then + log "Serveur démarré en $((SECONDS - debut)) s."; return 0 + fi + docker ps --format '{{.Names}}' | grep -qx "$CONTENEUR" || { log "Conteneur arrêté pendant le démarrage."; return 1; } + done + log "Pas de 'Done' après 10 min."; return 1 +} + +verifier_log() { + local depuis="$1" ok=0 l + l=$(docker logs --since "$depuis" "$CONTENEUR" 2>&1) + echo "$l" | grep -q 'Done (' || { log "KO : pas de démarrage complet"; ok=1; } + echo "$l" | grep -qiE 'Mixin apply.*failed|InvalidInjectionException|Crash report|Failed to load mod' && { log "KO : erreur de mod/mixin"; ok=1; } + echo "$l" | grep -q '\[GastinelTpa\] Téléportations chargées' || { log "KO : GastinelTpa non chargé"; ok=1; } + echo "$l" | grep -q '\[GastinelAuth\] Mod initialisé' || { log "KO : GastinelAuth non initialisé"; ok=1; } + for _ in 1 2 3 4 5 6; do + docker logs --since "$depuis" "$CONTENEUR" 2>&1 | grep -q 'Voice chat server started at port 24454' && break; sleep 5 + done + docker logs --since "$depuis" "$CONTENEUR" 2>&1 | grep -q 'Voice chat server started at port 24454' || { log "KO : chat vocal non démarré"; ok=1; } + for c in "spawn" "rtp" "tpa" "tpaccept"; do + if rcon "$c" | grep -q 'Unknown or incomplete command'; then log "KO : commande /$c absente"; ok=1; else log "Commande /$c : présente"; fi + done + return $ok +} + +retour_arriere() { + log "RETOUR ARRIÈRE : jar 1.1.0 + ancienne config" + rm -f "$MODS/$NOUVEAU" + [ -f "$MODS/$ANCIEN.$SUFFIXE" ] && mv -f "$MODS/$ANCIEN.$SUFFIXE" "$MODS/$ANCIEN" + [ -f "$CFG.$SUFFIXE" ] && cp -f "$CFG.$SUFFIXE" "$CFG" + local t; t=$(date -u +%Y-%m-%dT%H:%M:%SZ) + redemarrer_et_attendre "$t" || log "ERREUR : redémarrage impossible après retour arrière, intervention manuelle." + rcon list +} + +appliquer_config() { + # recharge spawn/rtp = 1 s (sed limité à la section), puis sections [recharge] et [tpa] si absentes. + sed -i '/^\[spawn\]/,/^\[/ s/^\(\s*rechargeSecondes\s*=\s*\).*/\11/' "$CFG" + sed -i '/^\[rtp\]/,/^\[/ s/^\(\s*rechargeSecondes\s*=\s*\).*/\11/' "$CFG" + grep -q '^\[recharge\]' "$CFG" || printf '\n[recharge]\n\tafficherMessageRecharge = false\n' >> "$CFG" + grep -q '^\[tpa\]' "$CFG" || printf '\n[tpa]\n\tdelaiSecondes = 1\n' >> "$CFG" +} + +if [ "${1:-}" = "--retour" ]; then + prevenir_et_sauver + retour_arriere + exit 0 +fi + +[ -f "$SRC/$NOUVEAU" ] || { log "Jar manquant : $SRC/$NOUVEAU"; exit 1; } +[ -f "$MODS/$ANCIEN" ] || { log "Ancien jar absent : $MODS/$ANCIEN (déjà déployé ?)"; exit 1; } +[ -f "$CFG" ] || { log "Config absente : $CFG"; exit 1; } +verifier_pas_de_generation + +mkdir -p "$SAUV" +cp -a "$CFG" "$SAUV/gastineltpa-server.toml.$(date +%Y%m%d-%H%M%S)" +log "Config sauvegardée dans $SAUV" + +prevenir_et_sauver +cp -a "$CFG" "$CFG.$SUFFIXE" +mv -f "$MODS/$ANCIEN" "$MODS/$ANCIEN.$SUFFIXE" +cp "$SRC/$NOUVEAU" "$MODS/$NOUVEAU" +appliquer_config +log "Jar remplacé (ancien : $ANCIEN.$SUFFIXE), config mise à jour (recharge 1 s, délai TPA 1 s)." + +DEBUT=$(date -u +%Y-%m-%dT%H:%M:%SZ) +ARRET=$(date '+%T') +if redemarrer_et_attendre "$DEBUT" && verifier_log "$DEBUT"; then + log "DÉPLOIEMENT OK (arrêt à $ARRET, de nouveau disponible à $(date '+%T'))." + rcon list +else + log "DÉPLOIEMENT KO : retour arrière automatique." + docker logs --since "$DEBUT" "$CONTENEUR" 2>&1 | grep -iE 'error|exception' | head -30 || true + retour_arriere + exit 1 +fi diff --git a/deployer-tpa-1-2-0.sh b/deployer-tpa-1-2-0.sh new file mode 100644 index 0000000..e24514b --- /dev/null +++ b/deployer-tpa-1-2-0.sh @@ -0,0 +1,184 @@ +#!/bin/bash +# Déploie GastinelTpa 1.2.0 sur cornafserver (inclut la 1.1.1 : recharge 1 s silencieuse, délai TPA caché, messages). +# Nouveautés 1.2.0 : /tpacancel, homes (/sethome /home /delhome /homes), protection RTP, message de mort privé. +# +# bash deployer-tpa-1-2-0.sh # déploie (jar attendu à côté du script, dans ~/staging/deploiement-tpa-1-2-0/) +# bash deployer-tpa-1-2-0.sh --avec-guide # idem + copie le texte du /guide (gastinelmind-guide.json, voir plus bas) +# bash deployer-tpa-1-2-0.sh --retour # remet le jar 1.1.0 et l'ancienne config, puis redémarre +# +# Ne redémarre que minecraft-neoforge, avec : docker compose --env-file ~/server-infra/.env up -d --force-recreate +# (depuis ~/server-infra/stacks/minecraft-neoforge). Le conteneur est d'abord ARRÊTÉ proprement (compose stop) pour que +# l'édition de la config ne soit pas "corrigée" à chaud par le jar 1.1.0 encore en service (clés inconnues). +# Aucune commande de ce script ne touche aux autres conteneurs ni aux autres mods. +set -uo pipefail + +STACK="$HOME/server-infra/stacks/minecraft-neoforge" +ENVFILE="$HOME/server-infra/.env" +DATA="$STACK/data" +MODS="$DATA/mods" +CFG="$DATA/config/gastineltpa-server.toml" +GUIDE="$DATA/config/gastinelmind-guide.json" +SRC="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SUFFIXE="avant-tpa-1-2-0" +CONTENEUR="minecraft-neoforge" +NOUVEAU="gastineltpa-neoforge-1.21.1-1.2.0.jar" +ANCIEN="gastineltpa-neoforge-1.21.1-1.1.0.jar" +SAUV="$HOME/staging/sauvegardes-$SUFFIXE" +AVEC_GUIDE=0 +RETOUR=0 +for a in "$@"; do + case "$a" in + --retour) RETOUR=1 ;; + --avec-guide) AVEC_GUIDE=1 ;; + *) echo "Option inconnue : $a"; exit 1 ;; + esac +done + +log() { echo "[$(date '+%F %T')] $*"; } +rcon() { docker exec "$CONTENEUR" rcon-cli "$@" 2>/dev/null || true; } +compose() { (cd "$STACK" && docker compose --env-file "$ENVFILE" "$@"); } + +prevenir_et_sauver() { + local n; n=$(rcon list | sed -n 's/.*There are \([0-9]*\) of.*/\1/p' | head -1); n=${n:-0} + log "Joueurs connectés : $n"; rcon list + if [ "$n" -gt 0 ]; then + rcon say "Redémarrage du serveur dans 60 s (mise à jour : homes, /tpacancel, protection /rtp). Durée : environ 2 min." + sleep 30; rcon say "Redémarrage dans 30 s." + sleep 20; rcon say "Redémarrage dans 10 s. Sauvegarde du monde…" + sleep 10 + fi + rcon save-all flush + sleep 5 +} + +verifier_pas_de_generation() { + if docker logs --since 10m "$CONTENEUR" 2>&1 | grep -qiE "chunky.*(task|tâche).*(running|progress)|\[Chunky\].*[0-9]+\.[0-9]+%"; then + log "ERREUR : génération Chunky en cours. Abandon."; exit 2 + fi + local actifs + actifs=$(pgrep -aif "bonsai|tache.?75" | grep -v -e pgrep -e "sleep [0-9]" || true) + if [ -n "$actifs" ]; then log "ERREUR : processus Bonsai / tâche 75 en cours. Abandon."; exit 2; fi +} + +# Attend que le conteneur soit "healthy" ET que le serveur ait fini de démarrer ("Done ("). +attendre_sain() { + local depuis="$1" debut=$SECONDS st + for _ in $(seq 1 120); do + sleep 5 + st=$(docker inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{else}}sans-healthcheck{{end}}' "$CONTENEUR" 2>/dev/null || echo absent) + if [ "$st" = "healthy" ] && docker logs --since "$depuis" "$CONTENEUR" 2>&1 | grep -q 'Done ('; then + log "Serveur démarré et healthy en $((SECONDS - debut)) s."; return 0 + fi + if [ "$st" = "absent" ] || [ "$st" = "exited" ]; then log "Conteneur absent/arrêté pendant le démarrage ($st)."; return 1; fi + done + log "Pas healthy après 10 min."; return 1 +} + +redemarrer() { # recrée et démarre (compose), puis attend + local t; t=$(date -u +%Y-%m-%dT%H:%M:%SZ) + log "docker compose up -d --force-recreate ($CONTENEUR)" + compose up -d --force-recreate || { log "ERREUR : docker compose up a échoué."; return 1; } + attendre_sain "$t" +} + +verifier_log() { + local depuis="$1" ok=0 l c + l=$(docker logs --since "$depuis" "$CONTENEUR" 2>&1) + echo "$l" | grep -q 'Done (' || { log "KO : pas de démarrage complet"; ok=1; } + echo "$l" | grep -qiE 'Mixin apply.*failed|InvalidInjectionException|Crash report|Failed to load mod' && { log "KO : erreur de mod/mixin"; ok=1; } + echo "$l" | grep -q '\[GastinelTpa\] Téléportations chargées' || { log "KO : GastinelTpa non chargé"; ok=1; } + echo "$l" | grep -q '\[GastinelAuth\] Mod initialisé' || { log "KO : GastinelAuth non initialisé"; ok=1; } + echo "$l" | grep -qE 'Homes : .*illisible' && { log "KO : fichier de homes illisible"; ok=1; } + for _ in 1 2 3 4 5 6; do + docker logs --since "$depuis" "$CONTENEUR" 2>&1 | grep -q 'Voice chat server started at port 24454' && break; sleep 5 + done + docker logs --since "$depuis" "$CONTENEUR" 2>&1 | grep -q 'Voice chat server started at port 24454' || { log "KO : chat vocal non démarré"; ok=1; } + # Lancées depuis la console : une commande qui existe répond autre chose que "Unknown or incomplete command" + # (ex. "joueur requis"). Avec un argument factice pour tpa/tpahere (sinon "incomplete" même si elle existe). + for c in "spawn" "rtp" "tpa x" "tpahere x" "tpaccept" "tpadeny" "tpacancel" "sethome" "home" "delhome" "homes"; do + if rcon "$c" | grep -q 'Unknown or incomplete command'; then log "KO : commande /${c%% *} absente"; ok=1; else log "Commande /${c%% *} : présente"; fi + done + return $ok +} + +# Remet jar 1.1.0 + ancienne config (arrête d'abord le serveur) et redémarre. +retour_arriere() { + log "RETOUR ARRIÈRE : jar 1.1.0 + ancienne config" + compose stop -t 120 "$CONTENEUR" >/dev/null 2>&1 || true + rm -f "$MODS/$NOUVEAU" + [ -f "$MODS/$ANCIEN.$SUFFIXE" ] && mv -f "$MODS/$ANCIEN.$SUFFIXE" "$MODS/$ANCIEN" + [ -f "$CFG.$SUFFIXE" ] && cp -f "$CFG.$SUFFIXE" "$CFG" + redemarrer || log "ERREUR : redémarrage impossible après retour arrière, intervention manuelle." + rcon list +} + +appliquer_config() { + # Recharges /spawn et /rtp = 1 s (limité à chaque section), puis sections/clés absentes (idempotent). + sed -i '/^\[spawn\]/,/^\[/ s/^\([ \t]*rechargeSecondes[ \t]*=[ \t]*\).*/\11/' "$CFG" + sed -i '/^\[rtp\]/,/^\[/ s/^\([ \t]*rechargeSecondes[ \t]*=[ \t]*\).*/\11/' "$CFG" + grep -q '^\[recharge\]' "$CFG" || printf '\n[recharge]\n\tafficherMessageRecharge = false\n' >> "$CFG" + grep -q '^\[tpa\]' "$CFG" || printf '\n[tpa]\n\tdelaiSecondes = 1\n' >> "$CFG" + grep -q '^\[homes\]' "$CFG" || printf '\n[homes]\n\tmaximum = 3\n\trechargeSecondes = 1\n\tdelaiSecondes = 3\n' >> "$CFG" + if ! grep -q 'protectionSecondes' "$CFG"; then + awk '{ print } /^\[rtp\][ \t]*$/ && !fait { print "\tprotectionSecondes = 15"; print "\tprotectionFinSiAttaque = true"; fait = 1 }' \ + "$CFG" > "$CFG.nouveau" && cat "$CFG.nouveau" > "$CFG" && rm -f "$CFG.nouveau" + fi + log "Config appliquée : recharges 1 s, [recharge] afficherMessageRecharge=false, [tpa] delaiSecondes=1, [homes], rtp.protection*." + grep -nE '^\[|rechargeSecondes|afficherMessageRecharge|delaiSecondes|maximum|protection' "$CFG" || true +} + +if [ "$RETOUR" = 1 ]; then + [ -f "$MODS/$ANCIEN.$SUFFIXE" ] || { log "Rien à restaurer : $MODS/$ANCIEN.$SUFFIXE absent."; exit 1; } + prevenir_et_sauver + retour_arriere + exit 0 +fi + +[ -f "$SRC/$NOUVEAU" ] || { log "Jar manquant : $SRC/$NOUVEAU"; exit 1; } +[ -f "$MODS/$ANCIEN" ] || { log "Ancien jar absent : $MODS/$ANCIEN (déjà déployé ?)"; exit 1; } +[ -f "$CFG" ] || { log "Config absente : $CFG"; exit 1; } +[ -f "$ENVFILE" ] || { log "Fichier d'environnement absent : $ENVFILE"; exit 1; } +[ -f "$STACK/docker-compose.yml" ] || { log "docker-compose.yml absent dans $STACK"; exit 1; } +[ "$AVEC_GUIDE" = 0 ] || [ -f "$SRC/gastinelmind-guide.json" ] || { log "--avec-guide : $SRC/gastinelmind-guide.json absent"; exit 1; } +verifier_pas_de_generation + +mkdir -p "$SAUV" +HORO=$(date +%Y%m%d-%H%M%S) +cp -a "$CFG" "$SAUV/gastineltpa-server.toml.$HORO" +cp -a "$MODS/$ANCIEN" "$SAUV/$ANCIEN.$HORO" +log "Config et ancien jar sauvegardés dans $SAUV" + +prevenir_et_sauver + +# Section critique : le serveur est arrêté ; en cas d'échec quelconque on remet l'ancien état puis on redémarre. +ARRET=$(date '+%T') +log "Arrêt propre de $CONTENEUR (compose stop)" +if ! compose stop -t 120 "$CONTENEUR"; then + log "ERREUR : arrêt impossible, rien n'a été modifié."; exit 1 +fi +cp -a "$CFG" "$CFG.$SUFFIXE" +if mv -f "$MODS/$ANCIEN" "$MODS/$ANCIEN.$SUFFIXE" && cp "$SRC/$NOUVEAU" "$MODS/$NOUVEAU" && appliquer_config; then + log "Jar remplacé (ancien : $ANCIEN.$SUFFIXE)." +else + log "DÉPLOIEMENT KO : copie ou config impossible." + retour_arriere + exit 1 +fi + +DEBUT=$(date -u +%Y-%m-%dT%H:%M:%SZ) +if redemarrer && verifier_log "$DEBUT"; then + log "DÉPLOIEMENT OK (arrêt à $ARRET, de nouveau disponible à $(date '+%T'))." + rcon list +else + log "DÉPLOIEMENT KO : retour arrière automatique." + docker logs --since "$DEBUT" "$CONTENEUR" 2>&1 | grep -iE 'error|exception' | head -30 || true + retour_arriere + exit 1 +fi + +# Texte du /guide (relu à chaud par GastinelMindPNJ, aucun redémarrage requis). Seulement avec --avec-guide. +if [ "$AVEC_GUIDE" = 1 ]; then + if [ -f "$GUIDE" ]; then cp -a "$GUIDE" "$SAUV/gastinelmind-guide.json.$HORO"; fi + cp "$SRC/gastinelmind-guide.json" "$GUIDE" + log "Texte du /guide mis à jour (sauvegarde : $SAUV/gastinelmind-guide.json.$HORO)." +fi