game/htdocs/indexA.php

395 lines
14 KiB
PHP

<?php
if(!defined('INDEX')) define('INDEX', 1);
include('includes/common.php');
require_once(_FCORE."../tables.php");
//On vérifie que le serveur ne soit pas fermé
require('includes/fermerServeur.php');
$template->assign('url_serveur', $_SERVER['HTTP_HOST']);
//On vérifie si le client est connecté ou non sur le site
if (isset($sess) && isset($sess->values['connected']) && $sess->values['connected'] && !empty($sess->values['id']) && isset($sess->values['auth_level']) && !empty($sess->values['idPlan'])) {
//On fait des vérifications de sécurité
//require('includes/securite.php');
$chapeau = new bdd();
$chapeau->connexion();
$chapeau->db();
//Bandeau d'informations
$infos = $chapeau->query("SELECT * FROM `$table_infoshead`");
$template->assign('infos',$infos);
$template->assign('nbinfos',$chapeau->num_rows-1);
//Affichage de la version du jeu
$template->assign('version', VERSION);
//Affichage du nombre d'inscrits par race
$chapeau->unique_query("SELECT * FROM `$table_user` WHERE `race` = 'covenant'");
$nbcovie = $chapeau->num_rows;
$chapeau->unique_query("SELECT * FROM `$table_user` WHERE `race` = 'humain'");
$nbhumain = $chapeau->num_rows;
$template->assign('count',array('humains' => $nbhumain, 'covenants' => $nbcovie, 'serveurs' => 'cette'));
//Récupération d'informations au sujet de l'utilisateur
$id_user = $sess->values['id'];
$queryUser = $chapeau->unique_query("SELECT * FROM `$table_user` WHERE `id` = '$id_user'");
//On vérifie que le joueur ne soit pas en mode vacances forcé
if ($queryUser['mv'] || !$queryUser) {
$sess->values['connected'] = false;
$sess->put();
header('Location: ?mvf');
exit;
}
$race = $queryUser['race'];
$template->assign('auth_level', $sess->values['auth_level']);
$template->assign('race', $queryUser['race']);
$template->assign('user', $queryUser);
$tpsdejeu = time() - $queryUser['last_visite'];
$heur = floor($tpsdejeu/3600);
$min = floor(($tpsdejeu - $heur*3600)/60);
if ($heur > 0) $min = $heur.' h '.$min;
$template->assign('tpsdejeu', $min.' min');
if (isset($_POST['Cplanete'])) {
$idPlanTest = $_POST['Cplanete'];
$chapeau->escape($idPlanTest);
if ($chapeau->unique_query("SELECT * FROM `$table_planete` WHERE `id_user` = '$id_user' AND `id` = '$idPlanTest'")) {
$sess->values['idPlan'] = $idPlanTest;
$sess->put();
$template->assign('contenu', '<meta http-equiv="refresh" content="0"/>');
$template->assign('page','vp');
$template->display('game/vp.tpl');
exit;
}
}
$idPlan = $sess->values['idPlan'];
$queryPlanetes = $chapeau->query("SELECT * FROM `$table_planete` WHERE `id_user` = '$id_user'");
$queryPlanete = $chapeau->unique_query("SELECT * FROM `$table_planete` WHERE `id` = '$idPlan'");
$chapeau->query("SELECT * FROM `$table_sessions` WHERE `active` = '1'");
$enligne = $chapeau->num_rows;
$case = $queryPlanete["cases"];
$metal = $queryPlanete["metal"];
$cristal = $queryPlanete["cristal"];
$hydrogene = $queryPlanete["hydrogene"];
require_once(_FCORE."../ressources.php");
require_once(_FCORE."../noms.php");
require_once(_FCORE."../vars.php");
require_once(_FCORE."../constructions.php");
require_once(_FCORE."../flottes.php");
$queryPlanete = $chapeau->unique_query("SELECT * FROM `$table_planete` WHERE `id` = '$idPlan'");
$metal = $queryPlanete["metal"];
$cristal = $queryPlanete["cristal"];
$hydrogene = $queryPlanete["hydrogene"];
$queryPlanete["metalS"] = separerNombres($queryPlanete["metal"]);
$queryPlanete["cristalS"] = separerNombres($queryPlanete["cristal"]);
$queryPlanete["hydrogeneS"] = separerNombres($queryPlanete["hydrogene"]);
$queryPlanete["energieS"] = separerNombres($queryPlanete["energie"]);
$queryPlanete["nom_planete"] = htmlspecialchars($queryPlanete["nom_planete"]);
//Alerte si nouveaux messages
$queryMail = $chapeau->query("SELECT * FROM `$table_mail` WHERE `destinataire` = '".$queryUser['pseudo']."' AND `vu` = '1';");
$template->assign('alertMail', $chapeau->num_rows);
$template->assign('planete',$queryPlanete);
$template->assign('planetes',$queryPlanetes);
$template->assign('enligne',$enligne);
$template->assign('nomsressources',$ressourc);
//Calcul du nombre de cases restantes
$coun = count($batiment);
$caseRest = $queryPlanete['cases'];
for ($i=0 ; $i<$coun ; $i++) {
$caseRest -= $queryPlanete[$batimentVAR[$i]];
}
$template->assign('caseRest',$case-$caseRest);
if (!isset($_GET['p'])) $_GET['p'] = '';
//Isolement de la planète
$queryPlanete['isolement'] = explode(' ', $queryPlanete['isolement']);
if (time() > $queryPlanete['isolement'][0]) {
if (!isset($queryPlanete['isolement'][1]) || (time() > $queryPlanete['isolement'][1] && date('dmY') != date('dmY', $queryPlanete['isolement'][0]))) {
$nbPlan = count($queryPlanetes);
$numP = 0;
for ($i=0 ; $i<$nbPlan ; $i++) {
if ($queryPlanetes[$i]['id'] == $queryPlanete['id']) $numP = $i;
}
if ($numP > 10) {
switch($numP){
case 11: $tps = 2; break;
case 12: $tps = 4; break;
case 13: $tps = 6; break;
case 14: $tps = 8; break;
case 15: $tps = 12; break;
case 16: $tps = 16; break;
case 17: $tps = 20; break;
default: $tps = 24;
}
$debut = mktime(rand(0, 24-$tps), 0, 0, date('n'), date('j'), date('Y'));
$fin = $debut + $tps * 3600;
$chapeau->query("UPDATE `$table_planete` SET `isolement` = '$debut $fin' WHERE `id` = '$idPlan' LIMIT 1 ;");
$queryPlanete['isolement'][0] = $debut;
if (time() > $queryPlanete['isolement'][0]) $queryPlanete['isolement'][1] = $fin;
}
}
if (isset($queryPlanete['isolement'][1]) && time() < $queryPlanete['isolement'][1] && $_GET['p'] != 'rename' && $_GET['p'] != 'accueil' && $_GET['p'] != 'arbre' && $_GET['p'] != 'prochainement' && $_GET['p'] != 'options' && $_GET['p'] != 'messagerie' && $_GET['p'] != 'envoyer' && $_GET['p'] != 'classement' && $_GET['p'] != 'bugs' && $_GET['p'] != 'deconnexion') {
$template->assign('message','Impossible de rentrer en contat avec cette planète. Réessayez plus tard.');
$template->assign('titre','Planète isolée');
$template->assign('couleur','red');
$template->display('game/erreur.tpl');
exit;
}
}
switch($_GET['p']){
case 'prochainement':
$page = 'prochainement';
$titre = 'Prochainement';
break;
case 'version':
include('game/version.php');
break;
case 'rename':
include('game/rename.php');
break;
case 'description':
include('game/description.php');
break;
case 'batiments':
include('game/batiments.php');
break;
case 'chantierspatial':
include('game/chantierspatial.php');
break;
case 'defenses':
include('game/defenses.php');
break;
case 'laboratoire':
include('game/laboratoire.php');
break;
case 'arbre':
include('game/arbre.php');
break;
case 'ressources':
include('game/ressources.php');
break;
case 'flotte':
include('game/flotte.php');
break;
case 'carte':
include('game/carte.php');
break;
case 'options':
include('game/options.php');
break;
case 'changeopt':
include('game/options_change.php');
break;
case 'messagerie':
include('game/messagerie.php');
break;
case 'envoyer':
include('game/envoyer.php');
break;
case 'alliances':
include('game/alliances.php');
break;
case 'classement':
include('game/classement.php');
break;
case 'bugs':
include('game/bugs.php');
break;
case 'chat':
$page = 'chat'; $titre = 'Chat';
break;
case 'faq':
include('game/aide.php');
break;
case 'simulateur':
include('game/simulateur.php');
break;
case 'deconnexion':
include('game/logout.php');
break;
case 'operateur':
include('game/operateur.php');
break;
case "conditions":
include('game/conditions.php');
break;
case "regles":
include('game/regles.php');
break;
default:
include('game/accueil.php');
}
$template->assign('page',$page);
$template->assign('titre',$titre);
$template->display('game/'.$page.'.tpl');
$chapeau->deconnexion();
}
//Si le joueur est non-connecté ou déconnecté
else {
$chapeau = new bdd();
$chapeau->connexion();
$chapeau->db();
$chapeau->query("SELECT * FROM `$table_user` WHERE `race` = 'covenant';");
$nbcovie = $chapeau->num_rows;
$chapeau->query("SELECT * FROM `$table_user` WHERE `race` = 'humain';");
$template->assign('count',array('humains' => $chapeau->num_rows, 'covenants' => $nbcovie, 'serveurs' => '1'));
if (isset($_POST['HB_login']) && isset($_POST['HB_password'])) {
$HB_login = $_POST['HB_login'];
$HB_password = $_POST['HB_password'];
$chapeau->escape($HB_login);
$chapeau->escape($HB_password);
if (empty($HB_login) || empty($HB_password)) {
$template->assign('message','Nom d\'utilisateur ou mot de passe incorrect.');
$template->assign('couleur','red');
$template->display('cms/erreur.tpl');
exit;
}
else {
//Limiter le nombre de personnes en ligne simutanément
/*$chapeau->query("SELECT * FROM $table_sessions WHERE active = '1' AND var_session != '';");
if ($chapeau->num_rows > 750) {
$template->assign('message','Il y a actuellement trop de monde connecté sur Halo-Battle. Pour permettre aux joueurs une navigation convenable, nous vous remercions de revenir plus tard.<br /><br /><i>Un système de file d\'attente sera bientôt mis en place pour permettre d\'avoir accès au jeu dans un délais raisonable.</i>');
$template->assign('couleur','red');
$template->display('cms/erreur.tpl');
exit;
}*/
$HB_password = sha1(strtoupper($HB_login).':'.$HB_password);
$resultat = $chapeau->unique_query("SELECT * FROM `$table_user` WHERE `pseudo` = '$HB_login' AND `mdp` = '$HB_password';");
if ($resultat) {
$id = $resultat['id'];
$time = time();
$ip = $_SERVER["REMOTE_ADDR"];
$chapeau->query("UPDATE `$table_user` SET `last_visite` = '$time', `last_ip` = '$ip' WHERE `id` = '$id';");
$reqPlan = $chapeau->query("SELECT * FROM `$table_planete` WHERE `id_user` = '$id';");
$resultatP = $reqPlan[0];
if ($resultat['mv'] != 0) {
if ($resultat['last_visite']+259200 > time() && $resultat['auth_level'] < 2) {
if ($resultat['mv'] == 2) $template->assign('message','Un opérateur a placé votre compte en mode vacances pour '.$resultat['raisonmv'].'. Vous ne pouvez pas vous reconnecter sur votre compte avant le<br />'.strftime("%A %d %B à %H:%M", $resultat['last_visite']+259200));
else $template->assign('message','Vous ne pouvez pas sortir du mode vacances avant le<br />'.strftime("%A %d %B à %H:%M", $resultat['last_visite']+259200));
$template->assign('couleur','red');
$template->display('game/erreur.tpl');
exit;
}
$chapeau->query("UPDATE `$table_user` SET `mv` = '0' WHERE `id` = '$id';");
$chapeau->query("UPDATE `$table_planete` SET `timestamp` = '".time()."' WHERE `id_user` = '$id';");
//On fait repartir à 0 les files d'attente
include_once('Class/class.gerefile.php');
$cntplan = count($reqPlan);
for ($i = 0; $i < $cntplan; $i++) {
if (!empty($reqPlan[$i]['file_bat'])) {
$file = unserialize($reqPlan[$i]['file_bat']);
$file->timestamp = time();
$fileBat = serialize($file);
$chapeau->escape($fileBat);
}
else $fileBat = '';
if (!empty($reqPlan[$i]['file_tech'])) {
$file = unserialize($reqPlan[$i]['file_tech']);
$file->timestamp = time();
$fileTech = serialize($file);
$chapeau->escape($fileTech);
}
else $fileTech = '';
if (!empty($reqPlan[$i]['file_cas'])) {
$file = unserialize($reqPlan[$i]['file_cas']);
$file->timestamp = time();
$fileCas = serialize($file);
$chapeau->escape($fileCas);
}
else $fileCas = '';
if (!empty($reqPlan[$i]['file_vais'])) {
$file = unserialize($reqPlan[$i]['file_vais']);
$file->timestamp = time();
$fileVais = serialize($file);
$chapeau->escape($fileCas);
}
else $fileVais = '';
if (!empty($reqPlan[$i]['file_ter'])) {
$file = unserialize($reqPlan[$i]['file_ter']);
$file->timestamp = time();
$fileTer = serialize($file);
$chapeau->escape($fileTer);
}
else $fileTer = '';
$idPlan = $reqPlan[$i]['id'];
$chapeau->query("UPDATE `$table_planete` SET `file_bat` = '$fileBat', `file_tech` = '$fileTech', `file_cas` = '$fileCas', `file_vais` = '$fileVais', `file_ter` = '$fileTer' WHERE `id` = '$idPlan';");
}
}
$chapeau->query("INSERT INTO `$table_registre_identification` (`id_util`,`ip`) VALUES ('".$id."','".$ip."')");
$sess->values['connected'] = TRUE;
$sess->values['id'] = $resultat['id'];
$id_user = $sess->values['id'];
$sess->values['idPlan'] = $resultatP['id'];
$idPlan = $sess->values['idPlan'];
$sess->values['auth_level'] = $resultat['auth_level'];
$sess->put();
header('Location: ./?p=accueil');
exit;
}
else {
$template->assign('message','Nom d\'utilisateur ou mot de passe incorrect.');
$template->assign('couleur','red');
$template->display('cms/erreur.tpl');
exit;
}
}
}
if (!isset($_GET['p'])) $_GET['p'] = '';
switch($_GET['p']){
//Serveur principal
/* case "validation":
include('game/validation.php');
break;
case "inscription":
include('game/inscription.php');
break;
case "oubliemdp":
header('Location: http://battle.halo.fr/?p=oubliemdp');
break;*/
//Serveur de jeu
case "njoueur":
include('game/njoueur.php');
break;
case "inscription":
header('Location: http://halo-battle.s-fr.com/?p=inscription');
exit;
break;
case "oubliemdp":
include('game/oubliemdp.php');
break;
//Tous serveurs
case "conditions":
include('game/conditions.php');
break;
case "regles":
include('game/regles.php');
break;
default:
$page = 'mini';
}
$template->display('cms/'.$page.'.tpl');
$chapeau->deconnexion();
}
?>