From 20af83d2ae94378ebe0a4753d0e0813c4cd34bbe Mon Sep 17 00:00:00 2001 From: Nigel Sheldon Date: Fri, 1 Jan 2021 14:25:11 +0100 Subject: [PATCH] =?UTF-8?q?Ajoute=20un=20syst=C3=A8me=20de=20cron=20pour?= =?UTF-8?q?=20calculer=20le=20classement=20tous=20les=20jours,=20voir=20pl?= =?UTF-8?q?us=20souvent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +++ cron/classement.php | 16 ++++++++++++++++ docker-compose.yml | 1 + onyx2/load.php | 4 +++- onyx2/modules/db/mysql.class.php | 10 ++++++++++ 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 cron/classement.php diff --git a/README.md b/README.md index 9b5071a..291969a 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,6 @@ vous connecter au serveur MySQL via `docker exec -it game_mariadb_1 mysql --user et récupérer votre jeton d'activation via `select id_activ from user_inscriptions WHERE pseudo LIKE 'VOTRE_PSEUDO_A_REMPLACER';` une fois l'ID récupérer, rendez-vous à l'adresse http://localhost:8080/?p=validation&i=VOTRE_ID (pensez bien à modifier l'id dans l'URL). + +## Installer +Un cron doit être rajouté sur la machine hôte pour calculer le classement des joueurs, en éxécutant le fichier `cron/classement.php` aussi souvent qu'il vous plaira (ou aussi souvent que votre CPU le permettra). diff --git a/cron/classement.php b/cron/classement.php new file mode 100644 index 0000000..6f938ec --- /dev/null +++ b/cron/classement.php @@ -0,0 +1,16 @@ +update_classement(); +$bdd->deconnexion(); diff --git a/docker-compose.yml b/docker-compose.yml index 1f8e5f5..9c34834 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,6 +28,7 @@ services: volumes: - ./htdocs:/usr/src/hb-main/htdocs:rw - ./onyx2:/usr/src/hb-main/onyx2:rw + - ./cron:/usr/src/hb-main/cron:rw # make cache and compile writable + don't add file to local host - /usr/src/hb-main/onyx2/cache - /usr/src/hb-main/onyx2/log diff --git a/onyx2/load.php b/onyx2/load.php index 536ada1..7a977a7 100644 --- a/onyx2/load.php +++ b/onyx2/load.php @@ -50,7 +50,9 @@ if ($cached['check'] == md5_file(ONYX.'config/root.xml').md5_file(ONYX.'modules/ //$xml->validate(); if ($root = $xml->documentElement->getAttribute('root')) { - if ($root == substr(FILE, 0, strlen($root))) { + // Autorise les fichiers dans les dossiers htdocs/ et cron/ + $cron = str_replace("htdocs", "cron", $root); + if ($root == substr(FILE, 0, strlen($root)) || $cron == substr(FILE, 0, strlen($cron))) { define('ROOT', $root); $search = substr(FILE, strlen($root)); diff --git a/onyx2/modules/db/mysql.class.php b/onyx2/modules/db/mysql.class.php index d355fc8..fedbc8a 100644 --- a/onyx2/modules/db/mysql.class.php +++ b/onyx2/modules/db/mysql.class.php @@ -193,4 +193,14 @@ class BDD return mysqli_affected_rows($this->session); } + + public function update_classement() + { + if (!$this->session) { + return false; + } + global $table_user; + $query = "SET @p=0; UPDATE $table_user SET place_points = (@p:=@p+1) ORDER BY points DESC;"; + mysqli_multi_query($this->session, $query); + } }