From a3ac838a19d98eea8476198698dd65c19794d2dd Mon Sep 17 00:00:00 2001 From: Nigel Sheldon Date: Sun, 3 Jan 2021 18:43:43 +0100 Subject: [PATCH] =?UTF-8?q?Correctifs=20sur=20la=20page=20de=20pr=C3=A9par?= =?UTF-8?q?ation=20d'envoie=20des=20flotte?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/ajax_flotte.php | 83 ++++++++++++++----------- htdocs/js/flotte.js | 19 +++++- onyx2/include/Class/Donnees/spatial.php | 12 ++-- onyx2/include/Class/flotte.php | 32 +++++++--- onyx2/include/flottes.php | 24 ++++++- onyx2/include/game/flottes/preparer.php | 5 ++ onyx2/include/server/messagerie.php | 4 +- onyx2/tpl/game/flotte2.tpl | 4 +- 8 files changed, 125 insertions(+), 58 deletions(-) diff --git a/htdocs/ajax_flotte.php b/htdocs/ajax_flotte.php index 669ac90..3ab42e3 100644 --- a/htdocs/ajax_flotte.php +++ b/htdocs/ajax_flotte.php @@ -1,16 +1,20 @@ values['connected']) && $sess->values['connected'] && !empty($sess->values['id']) && !empty($sess->level) && !empty($sess->values['idPlan'])) { +if (isset($SESS) && isset($SESS->values['connected']) && $SESS->values['connected'] && !empty($SESS->values['id']) && !empty($SESS->level) && !empty($SESS->values['idPlan'])) { + $idPrep = gpc("cds_temp", "post"); $json = new Services_JSON(); $nbtrajet = 2; - if (empty($config['flottes']) && $sess->level <= 1) { + if (empty($config['flottes']) && $SESS->level <= 1) { $datas = array( 'root' => array( 'destination' => '::', @@ -28,8 +32,7 @@ if (isset($sess) && isset($sess->values['connected']) && $sess->values['connecte $destin = gpc('fav_dest', 'post'); $chapeau = new bdd(); - $chapeau->connexion(); - $idPlan = $sess->values['idPlan']; + $idPlan = $SESS->values['idPlan']; $queryPlanete = $chapeau->unique_query("SELECT * FROM $table_planete WHERE id = '$idPlan'"); if (!empty($destin)) { $chapeau->escape($destin); @@ -45,18 +48,11 @@ if (isset($sess) && isset($sess->values['connected']) && $sess->values['connecte $start_ss = $queryPlanete['ss']; $start_position = $queryPlanete['position']; - $met = gpc('met', 'post'); - $cri = gpc('cri', 'post'); - $hyd = gpc('hyd', 'post'); - if (!empty($sess->values['flcontenu']) && $met+$cri+$hyd >= 0 && $met >= 0 && $cri >= 0 && $hyd >= 0) { - $places = $sess->values['flcontenu'] - ($met+$cri+$hyd); - } else { - $places = 'inconnu'; - } - - - - if (empty($sess->values['fltime']) || $sess->values['fltime'] + 600 < time() || empty($sess->values['flnbvais']) || empty($sess->values['flvitesse']) && isset($sess->values['auth_level'])) { + if (empty($SESS->values["prepFlottes"][$idPrep]['time']) || + $SESS->values["prepFlottes"][$idPrep]['time'] + 1200 < time() || + empty($SESS->values["prepFlottes"][$idPrep]['nbVaisseaux']) || + empty($SESS->values["prepFlottes"][$idPrep]['vitesse']) && + isset($SESS->values['auth_level'])) { $datas = array( 'root' => array( 'destination' => $destinRapid, @@ -64,7 +60,7 @@ if (isset($sess) && isset($sess->values['connected']) && $sess->values['connecte 'deblok' => 'Une erreur est survenue lors de la création de la flotte. Veuillez recommencer', 'conso' => '-', 'tactique' => '', - 'places' => separerNombres($places) + 'places' => '', ) ); } elseif (empty($_POST['nom']) || preg_replace('@[^a-zA-Z0-9_ ]@i', '', $_POST['nom']) != $_POST['nom']) { @@ -75,10 +71,10 @@ if (isset($sess) && isset($sess->values['connected']) && $sess->values['connecte 'deblok' => 'Nom de la flotte incorrect !', 'conso' => '-', 'tactique' => '', - 'places' => separerNombres($places) + 'places' => '', ) ); - } elseif ($_POST['galaxie'] > MAX_AMAS || $_POST['ss'] > MAX_SYSTEME || $_POST['pos'] > MAX_PLANETE || $_POST['galaxie'] < 0 || $_POST['ss'] < 1 || $_POST['pos'] < 1 || ($_POST['galaxie'] < 1 && $sess->values['auth_level'] < 6)) { + } elseif ($_POST['galaxie'] > $VAR['nb_amas'] || $_POST['ss'] > $VAR['nb_systeme'] || $_POST['pos'] > $VAR['nb_planete'] || $_POST['galaxie'] < 0 || $_POST['ss'] < 1 || $_POST['pos'] < 1 || ($_POST['galaxie'] < 1 && $SESS->values['auth_level'] < 6)) { $datas = array( 'root' => array( 'destination' => $destinRapid, @@ -86,23 +82,37 @@ if (isset($sess) && isset($sess->values['connected']) && $sess->values['connecte 'deblok' => 'Corrigez la destination !', 'conso' => '-', 'tactique' => '', - 'places' => separerNombres($places) + 'places' => '', ) ); } else { $_POST['vitesse'] /= 100; - $temps = vais_tempsDeplacement($start_galaxie, $start_ss, $start_position, $_POST['galaxie'], $_POST['ss'], $_POST['pos'], $sess->values['flvitesse'], $_POST['vitesse'], $sess->values['flpreparation'], $sess->values['flchauffe']); + + $planete = new planete($idPlan); + $flotte = new flotte(); + $temps = $flotte->calc_deplacement($planete, $_POST['galaxie'], $_POST['ss'], $_POST['pos'], $_POST['vitesse'], $SESS->values["prepFlottes"][$idPrep]['vaisseaux'], 1000); if ($temps <= 0) { $temps = 454; } - $conso = vais_conso($temps, $sess->values['flnbvais'])*$_POST['vitesse']/45; - $places -= ceil($conso*$nbtrajet); + $conso = $flotte->calc_deplacement($planete, $_POST['galaxie'], $_POST['ss'], $_POST['pos'], $_POST['vitesse'], $SESS->values["prepFlottes"][$idPrep]['vaisseaux'], 1000, false, true); + // $conso renvoi le temps ET la conso dans un array + $conso = intval($conso[1]); + + $met = intval(gpc('met', 'post')); + $cri = intval(gpc('cri', 'post')); + $hyd = intval(gpc('hyd', 'post')); + $places = $flotte->calcStockage($SESS->values["prepFlottes"][$idPrep]['vaisseaux'], $planete); + $places -= ceil($conso * $nbtrajet); + if (($met+$cri+$hyd) > 0) { + $places -= ($met+$cri+$hyd); + } $tactique = ''; if ($_POST['mission'] == '1') { $tactique = '
'; } - $cds = sha1('flotte'.$conso.'ß10'.time().'|HB;'.rand(10, 99).$temps); - $sess->values['flcds'] = $cds; - $sess->put(); + $SESS->values['flcds'] = $idPrep; + $SESS->put(); $datas = array( 'root' => array( 'destination' => $destinRapid, 'temps' => affTemp(floor($temps)), - 'deblok' => '', - 'conso' => separerNombres(ceil($conso*2)), + 'deblok' => '', + 'conso' => ceil($conso*2), 'tactique' => $tactique, - 'places' => separerNombres($places) + 'places' => $places ) ); } diff --git a/htdocs/js/flotte.js b/htdocs/js/flotte.js index 061a7b1..129e9c7 100644 --- a/htdocs/js/flotte.js +++ b/htdocs/js/flotte.js @@ -91,11 +91,26 @@ window.onload = function(){ function tempsFlotte() { document.getElementById('deblok').innerHTML = '...'; + var url_string = (window.location.href).toLowerCase(); + var url = new URL(url_string); + var cds = url.searchParams.get("c"); new Ajax.Request( 'ajax_flotte.php', { method: 'post', - parameters: {fav_dest: document.getElementById('fav_dest').value, nom: document.getElementById('nom').value, mission: document.getElementById('mission').value, met: document.getElementById('metal').value, cri: document.getElementById('cristal').value, hyd: document.getElementById('hydrogene').value, galaxie: document.getElementById('amas').value, ss: document.getElementById('ss').value, pos: document.getElementById('plan').value, vitesse: document.getElementById('vitesse').value}, + parameters: { + cds_temp: cds, + fav_dest: document.getElementById('fav_dest').value, + nom: document.getElementById('nom').value, + mission: document.getElementById('mission').value, + met: document.getElementById('metal').value, + cri: document.getElementById('cristal').value, + hyd: document.getElementById('hydrogene').value, + galaxie: document.getElementById('amas').value, + ss: document.getElementById('ss').value, + pos: document.getElementById('plan').value, + vitesse: document.getElementById('vitesse').value + }, onSuccess: function(transport, json) { document.getElementById('destination').innerHTML = json.root.destination; document.getElementById('temps').innerHTML = json.root.temps; @@ -107,4 +122,4 @@ function tempsFlotte() { } } ); -} \ No newline at end of file +} diff --git a/onyx2/include/Class/Donnees/spatial.php b/onyx2/include/Class/Donnees/spatial.php index 56c772b..60c625e 100644 --- a/onyx2/include/Class/Donnees/spatial.php +++ b/onyx2/include/Class/Donnees/spatial.php @@ -734,7 +734,7 @@ class dSpatial implements Donnees } - public static function tailleCales($id) + public static function tailleCales($id, surface $planete) { if ($planete->race == "humain") { switch ($id) { @@ -781,7 +781,7 @@ class dSpatial implements Donnees $vitesse = 15000; break; default: - trigger_error("Vaisseau ".$id." introuvable dans les données", E_USER_ERROR); + $vitesse = 0; } } else { switch ($id) { @@ -837,7 +837,7 @@ class dSpatial implements Donnees $vitesse = 20000000; break; default: - trigger_error("Vaisseau ".$id." introuvable dans les données", E_USER_ERROR); + $vitesse = 0; } } @@ -846,7 +846,7 @@ class dSpatial implements Donnees } - public static function vitesseP($id) + public static function vitesseP($id, surface $planete) { if ($planete->race == "humain") { switch ($id) { @@ -957,7 +957,7 @@ class dSpatial implements Donnees return $vitesse; } - public static function vitesseS($id) + public static function vitesseS($id, surface $planete) { if ($planete->race == "humain") { switch ($id) { @@ -1068,7 +1068,7 @@ class dSpatial implements Donnees return $vitesse; } - public static function vitesseG($id) + public static function vitesseG($id, surface $planete) { if ($planete->race == "humain") { switch ($id) { diff --git a/onyx2/include/Class/flotte.php b/onyx2/include/Class/flotte.php index 1a7559c..aab618f 100644 --- a/onyx2/include/Class/flotte.php +++ b/onyx2/include/Class/flotte.php @@ -88,12 +88,13 @@ class Flotte public function calculer() { + global $planete; $this->nb_vais = 0; //Calcul de la capacité maximale d'embarquement de la flotte foreach ($this->vaisseaux as $key => $vais) { $this->nb_vais += $vais; - $this->contenuMax += dSpatial::tailleCales($key) * $vais; + $this->contenuMax += dSpatial::tailleCales($key, $planete) * $vais; } } @@ -265,20 +266,20 @@ class Flotte //Calcul du temps de déplacement entre planètes if ($start_planete->ss == $end_systeme && $start_planete->galaxie == $end_galaxie) { - $temps[0][$key] = (1000/dSpatial::vitesseP($key)) * (1 + 0.1 * $diff_position); + $temps[0][$key] = (1000/dSpatial::vitesseP($key, $start_planete)) * (1 + 0.1 * $diff_position); $temps[1][$key] = $temps[2][$key] = 0; } //Calcul du temps de déplacement entre système elseif ($start_planete->galaxie == $end_galaxie) { - $temps[0][$key] = (1000/dSpatial::vitesseP($key)) * (1 + 0.1 * ($diff_centre_position_start + $diff_centre_position_end)); - $temps[1][$key] = (2000/dSpatial::vitesseS($key)) * (2 + 1 * $diff_systeme); + $temps[0][$key] = (1000/dSpatial::vitesseP($key, $start_planete)) * (1 + 0.1 * ($diff_centre_position_start + $diff_centre_position_end)); + $temps[1][$key] = (2000/dSpatial::vitesseS($key, $start_planete)) * (2 + 1 * $diff_systeme); $temps[2][$key] = 0; } //Calcul du temps de déplacement entre galaxies else { - $temps[0][$key] = (1000/dSpatial::vitesseP($key)) * (1 + 0.1 * ($diff_centre_position_start + $diff_centre_position_end)); - $temps[1][$key] = (2000/dSpatial::vitesseS($key)) * (2 + 1 * ($diff_centre_systeme_start + $diff_centre_systeme_end)); - $temps[2][$key] = (5000/dSpatial::vitesseG($key)) * (2 + 1.5 * $diff_galaxie); + $temps[0][$key] = (1000/dSpatial::vitesseP($key, $start_planete)) * (1 + 0.1 * ($diff_centre_position_start + $diff_centre_position_end)); + $temps[1][$key] = (2000/dSpatial::vitesseS($key, $start_planete)) * (2 + 1 * ($diff_centre_systeme_start + $diff_centre_systeme_end)); + $temps[2][$key] = (5000/dSpatial::vitesseG($key, $start_planete)) * (2 + 1.5 * $diff_galaxie); } //Calcul du bonus pour le réacteur à combustion @@ -332,7 +333,7 @@ class Flotte } //Si les chasseurs peuvent rentrer dans les cales des vaisseaux, on les enlèves - if ($contenuDispo - ceil($conso[0]+$conso[1]+$conso[2]) - ($vaisseaux[4] * dSpatial::tailleCales(4) + $vaisseaux[5] * dSpatial::tailleCales(5)) >= ($vaisseaux[4] + $vaisseaux[5]) * 200) { + if ($contenuDispo - ceil($conso[0]+$conso[1]+$conso[2]) - ($vaisseaux[4] * dSpatial::tailleCales(4, $start_planete) + $vaisseaux[5] * dSpatial::tailleCales(5, $start_planete)) >= ($vaisseaux[4] + $vaisseaux[5]) * 200) { $temps[2][4] = $temps[2][5] = $temps[1][4] = $temps[1][5] = $temps[0][4] = $temps[0][5] = 0; } @@ -347,6 +348,21 @@ class Flotte } + public function calcStockage($vaisseaux, surface $planete) + { + global $LANG; + + $contenuMax = 0; + foreach ($vaisseaux as $key => $vais) { + if (!isset($LANG[$planete->race]["vaisseaux"]["noms_sing"][$key])) { + continue; + } + $contenuMax += dSpatial::tailleCales($key, $planete) * $vais; + } + return $contenuMax; + } + + public function check_mission() { //On vérifie qu'un calcul ne soit pas déjà en cours diff --git a/onyx2/include/flottes.php b/onyx2/include/flottes.php index 3ff81ff..ac65513 100644 --- a/onyx2/include/flottes.php +++ b/onyx2/include/flottes.php @@ -5,7 +5,29 @@ if (!defined('INDEX')) { } $bdd->reconnexion(); -$flottes = $bdd->query("SELECT id FROM $table_flottes WHERE (id_user = ".$planete->id_user." OR end_planete = ".$planete->id." OR id_alliance = ".$planete->id_alliance." OR end_planete = ".$planete->id_alliance.") AND (start_time + end_time) <= ".time()." AND last < ".(time()-10).";"); +$sql = ""; +if ($planete->id_user != null) { + $sql = "id_user = " . $planete->id_user . " "; +} +if ($planete->id != null) { + if ($sql != "") { + $sql .= " OR "; + } + $sql .= "end_planete = " . $planete->id . " "; +} +if ($planete->id_alliance != null) { + if ($sql != "") { + $sql .= " OR "; + } + $sql .= "id_alliance = " . $planete->id_alliance . " "; +} +if ($planete->id_alliance != null) { + if ($sql != "") { + $sql .= " OR "; + } + $sql .= "end_planete = " . $planete->id_alliance . " "; +} +$flottes = $bdd->query("SELECT id FROM $table_flottes WHERE (" . $sql . ") AND (start_time + end_time) <= ".time()." AND last < ".(time()-10).";"); $bdd->deconnexion(); if (!empty($flottes)) { diff --git a/onyx2/include/game/flottes/preparer.php b/onyx2/include/game/flottes/preparer.php index 6540043..32fe26e 100644 --- a/onyx2/include/game/flottes/preparer.php +++ b/onyx2/include/game/flottes/preparer.php @@ -7,6 +7,10 @@ if (!defined('INDEX')) { //Génération d'un ID unique pour identifier la flotte durant sa création $idPrep = random(); +//Supression des précédentes flottes, sinon il y a un risque de remplir le champs de BDD qui sauvegarde les flottes +$SESS->values["prepFlottes"] = null; +$SESS->values["prepFlottes"] = array(); + //Création du tableau de session $SESS->values["prepFlottes"][$idPrep] = array(); @@ -41,6 +45,7 @@ $SESS->values["prepFlottes"][$idPrep]['nbVaisseaux'] = $nombreVaisseau; $SESS->values['forceFlotte'] = false; $SESS->values["prepFlottes"][$idPrep]['time'] = time(); $SESS->values["prepFlottes"][$idPrep]['statut'] = 1; +$SESS->values["prepFlottes"][$idPrep]['vitesse'] = 100; // vitesse par défaut: 100% $SESS->put(); unset($nombreVaisseau, $key, $vaisseau, $v); diff --git a/onyx2/include/server/messagerie.php b/onyx2/include/server/messagerie.php index adecc6a..6f477bc 100644 --- a/onyx2/include/server/messagerie.php +++ b/onyx2/include/server/messagerie.php @@ -45,8 +45,8 @@ if ($onglet == "rapports") { } $bdd->reconnexion(); - $data = $bdd->query("SELECT * FROM $table_mail WHERE destinataire = ".$planete->id_user." AND expediteur = false AND vu != 's' ORDER BY id DESC;"); - $bdd->query("UPDATE $table_mail SET vu = 0 WHERE destinataire = ".$planete->id_user." AND expediteur = false AND vu != 's';"); + $data = $bdd->query("SELECT * FROM $table_mail WHERE destinataire = ".$planete->id_user." AND expediteur IS NULL AND vu != 's' ORDER BY id DESC;"); + $bdd->query("UPDATE $table_mail SET vu = 0 WHERE destinataire = ".$planete->id_user." AND expediteur IS NULL AND vu != 's';"); $bdd->deconnexion(); $template->assign('messages', $data); diff --git a/onyx2/tpl/game/flotte2.tpl b/onyx2/tpl/game/flotte2.tpl index e21742c..750d705 100644 --- a/onyx2/tpl/game/flotte2.tpl +++ b/onyx2/tpl/game/flotte2.tpl @@ -23,10 +23,10 @@

Envoyer

-
+
Temps de déplacement : -
Consomation : -
Complètez les champs ci-dessus
-{include file='game/footer.tpl'} \ No newline at end of file +{include file='game/footer.tpl'} -- 2.45.2