game/pages/ajax_flotte.php

82 lines
3.2 KiB
PHP
Raw Blame History

<?php
session_start();
$id = $_SESSION['id'];
$auth_level = $_SESSION['auth_level'];
$start_galaxie = $_SESSION['galaxy'];
$start_ss = $_SESSION['ss'];
$start_position = $_SESSION['pos'];
if (!isset($_SESSION['flotte_cdsL'])) $_SESSION['flotte_cdsL'] = '';
require('../fonctions.php');
require('../Class/JSON.php');
$json = new Services_JSON();
if (!isset($_SESSION['FL_time']) || $_SESSION['FL_time'] + 600 < time() || !isset($_SESSION['FL_nbvais']) || !isset($_SESSION['FL_vitesse']) || !isset($_POST['galaxie']) || !isset($_POST['ss']) || !isset($_POST['pos']) || !isset($_POST['vitesse']) || !is_numeric($_POST['galaxie']) || !is_numeric($_POST['ss']) || !is_numeric($_POST['pos']) || !is_numeric($_POST['vitesse'])) {
$datas = array(
'root' => array(
'temps' => '-',
'deblok' => '<b>Compl&egrave;tez les champs ci-dessus</b>',
'conso' => '-'
)
);
}
elseif ($_POST['galaxie'] > 1 || $_POST['ss'] > 100 || $_POST['pos'] > 12 || $_POST['galaxie'] < 0 || $_POST['ss'] < 1 || $_POST['pos'] < 1 || ($_POST['galaxie'] < 1 && $auth_level < 6)) {
$datas = array(
'root' => array(
'temps' => '<span style="color: #FF0000;"><b>Lieu inaccessible</b></span>',
'deblok' => '<b>Corrigez la destination !</b>',
'conso' => '-'
)
);
}
else {
$_POST['vitesse'] /= 100;
$temps = vais_tempsDeplacement($start_galaxie,$start_ss,$start_position,$_POST['galaxie'],$_POST['ss'],$_POST['pos'],$_SESSION['FL_vitesse'],$_POST['vitesse'],$_SESSION['FL_preparation'],$_SESSION['FL_chauffe']);
$conso = vais_conso($temps, $_SESSION['FL_nbvais'])*($_POST['vitesse']*10);
//On recherche si la flotte va faire un aller-retour ou un aller simple
if (isset($_POST['mission']) && is_numeric($_POST['mission']) && ($_POST['mission'] == '3')) $nbtrajet = 1;
else $nbtrajet = 2;
if ($temps == 0)
$datas = array(
'root' => array(
'temps' => '<span style="color: #FF3333;"><b>Vous &ecirc;tes sur cette plan&egrave;te</b></span>',
'deblok' => '<b>Corrigez la destination !</b>',
'conso' => '-'
)
);
elseif (preg_replace('@[^a-zA-Z0-9_]@i', '', $_POST['nom']) != $_POST['nom'] || empty($_POST['nom']))
$datas = array(
'root' => array(
'temps' => affTemp(floor($temps)),
'deblok' => '<b>Nom de la flotte incorrect !</b>',
'conso' => separerNombres(ceil($conso*($_POST['vitesse']/100)*$nbtrajet))
)
);
/*elseif (empty($_POST['hyd']) || $_POST['hyd'] < $conso * 2)
$datas = array(
'root' => array(
'temps' => affTemp(floor($temps)),
'deblok' => '<b>Vous n\'avez pas embarqu&eacute; assez d\'hydrog&egrave;ne pour faire l\'aller-retour !</b>',
'conso' => separerNombres(floor($conso*($_POST['vitesse']/100)*$nbtrajet))
)
);*/
else {
$cds = sha1('flotte'.$conso.'<27>10'.time().'|HB;'.rand(10,99).$temps);
$_SESSION['flotte_cdsL'] = $cds;
if ($id == '46') setHistorique('Rapport Frederic PREP','G<>n<EFBFBD>ration code : SESSION : '.$_SESSION['flotte_cdsL'].' - cds : '.$cds);
$datas = array(
'root' => array(
'temps' => affTemp(floor($temps)),
'deblok' => '<input type="hidden" name="cds" value="'.$cds.'" /><input type="submit" value="Envoyer la flotte" class="bouton" />',
'conso' => separerNombres(ceil($conso*($_POST['vitesse']/100)*$nbtrajet))
)
);
}
}
header("X-JSON: ".$json->encode($datas));
?>