Version 1.9g

This commit is contained in:
nemunaire 2008-11-08 12:00:00 +01:00
commit 4c9814a99c
800 changed files with 237325 additions and 1949 deletions

View file

@ -0,0 +1,98 @@
<?php
/***************************************************************************
* class.planete.php
* -------------------
* begin : Jeudi 21 août 2008
* update : Dimanche 7 septembre 2008
* email : nemunaire@gmail.com
*
*
***************************************************************************/
class Planete extends User{
var $id,
$metal,
$cristal,
$hydrogene,
$batiments = array(),
$casernes = array(),
$terrestres = array(),
$vaisseaux = array();
/**
* Constructeur
* @param int $id id de la planète à importer
*
* @return void
* @access public
*/
function Planete($plan, $user){
global $batimentVAR, $casernenVAR, $nomterrnVAR, $nomvaisnVAR;
parent::User($user);
$this->id = $plan["id"];
$this->metal = $plan["metal"];
$this->cristal = $plan["cristal"];
$this->hydrogene = $plan["hydrogene"];
foreach($batimentVAR as $bat){
$this->batiments[] = $plan[$bat];
}
foreach($casernenVAR as $cas){
$this->casernes[] = $plan[$cas];
}
foreach($nomterrnVAR as $ter){
$this->terrestres[] = $plan[$ter];
}
foreach($nomvaisnVAR as $vais){
$this->vaisseaux[] = $plan[$vais];
}
}
function calculerBatiments(){
global $batimentCALC;
$pointsbat = 0;
$planete = $this;
foreach($this->batiments as $k => $n){
eval($batimentCALC[$k][0]);
eval($batimentCALC[$k][1]);
eval($batimentCALC[$k][2]);
$pointsbat += $a + $b + $c;
}
return $pointsbat;
}
function calculerCasernes(){
global $casernenCALC;
$pointscas = 0;
foreach($this->casernes as $k => $n){
$pointscas += ($casernenCALC[$k][0] + $casernenCALC[$k][1] + $casernenCALC[$k][2]) * $n;
}
return $pointscas;
}
function calculerTerrestres(){
global $nomterrnCALC;
$pointster = 0;
foreach($this->terrestres as $k => $n){
$pointster += ($nomterrnCALC[$k][0] + $nomterrnCALC[$k][1] + $nomterrnCALC[$k][2]) * $n;
}
return $pointster;
}
function calculerVaisseaux(){
global $nomvaisnCALC;
$pointsvai = 0;
foreach($this->vaisseaux as $k => $n){
$pointsvai += ($nomvaisnCALC[$k][0] + $nomvaisnCALC[$k][1] + $nomvaisnCALC[$k][2]) * $n;
}
return $pointsvai;
}
}
?>

48
game/cron/class.user.php Normal file
View file

@ -0,0 +1,48 @@
<?php
/***************************************************************************
* class.user.php
* ----------------
* begin : Dimanche 7 septembre 2008
* update : Dimanche 7 septembre 2008
* email : nemunaire@gmail.com
*
*
***************************************************************************/
class User{
var $id_user,
$technologies = array(),
$credits;
/**
* Constructeur
* @param int $id id de la planète à importer
*
* @return void
* @access public
*/
function User($user){
global $technoloVAR;
$this->id_user = $user["id"];
$this->credits = $user["credits"];
foreach($technoloVAR as $tech){
$this->technologies[] = $user[$tech];
}
}
function calculerTechnologies(){
global $technoloCALC;
$pointstech = 0;
$planete = $this;
foreach($this->batiments as $k => $n){
eval($technoloCALC[$k][0]);
eval($technoloCALC[$k][1]);
eval($technoloCALC[$k][2]);
$pointstech += $a + $b + $c;
}
return $pointstech;
}
}
?>

View file

@ -2,6 +2,9 @@
if(!defined('CRON')) { header('Location: ../'); exit; }
print 'Début de la génération du classement ; il est : '.date('d/m/Y H:i:s');
require_once(_FCORE."../game/cron/class.user.php");
require_once(_FCORE."../game/cron/class.planete.php");
//*
//Classement Joueurs
$bdd->connexion();
@ -9,10 +12,8 @@ $bdd->query("TRUNCATE TABLE $table_classement;");
$users = $bdd->query("SELECT * FROM $table_user;");
$bdd->deconnexion();
$cnt = $bdd->num_rows;
for($i = 0; $i < $cnt; $i++){
$id_user = $users[$i]['id'];
$queryUser = $users[$i];
foreach($users as $queryUser){
$id_user = $queryUser['id'];
$pointsbat = 0;
$pointsterr = 0;
$pointsvais = 0;
@ -21,76 +22,47 @@ for($i = 0; $i < $cnt; $i++){
$planetes = $bdd->query("SELECT * FROM $table_planete WHERE id_user = $id_user;");
$bdd->deconnexion();
$cntp = $bdd->num_rows;
for($j = 0; $j < $cntp; $j++){
$queryPlanete = $planetes[$j];
$nbbat = count($batimentVAR);
for($k = 0; $k < $nbbat; $k++){
if ($queryPlanete[$batimentVAR[$k]] == 0) continue;
else {
$n = $queryPlanete[$batimentVAR[$k]];
eval($batimentCALC[$k][0]);
eval($batimentCALC[$k][1]);
eval($batimentCALC[$k][2]);
$pointsbat += $a + $b + $c;
}
}
$nbterr = count($nomterrnVAR);
for($k = 0; $k < $nbterr; $k++){
if ($queryPlanete[$nomterrnVAR[$k]] == 0) continue;
else {
$n = $queryPlanete[$nomterrnVAR[$k]];
$pointsterr += ($nomterrnCALC[$k][0] + $nomterrnCALC[$k][1] + $nomterrnCALC[$k][2]) * $n;
}
}
$nbvais = count($nomvaisnVAR);
for($k = 0; $k < $nbvais; $k++){
if ($queryPlanete[$nomvaisnVAR[$k]] == 0) continue;
else {
$n = $queryPlanete[$nomvaisnVAR[$k]];
$pointsvais += ($nomvaisnCALC[$k][0] + $nomvaisnCALC[$k][1] + $nomvaisnCALC[$k][2]) * $n;
}
//Calcul des points par planète
if (!empty($planetes)) {
foreach($planetes as $planete){
$plan = new Planete($planete, $queryUser);
$pointsbat += $plan->calculerBatiments();
$pointsterr += $plan->calculerTerrestres();
$pointsvais += $plan->calculerVaisseaux();
}
}
$nbtech = count($technoloVAR);
$pointstech = 0;
for($k = 0; $k < $nbtech; $k++){
if ($queryUser[$technoloVAR[$k]] == 0) continue;
else {
$n = $queryUser[$technoloVAR[$k]];
eval($technoloCALC[$k][0]);
eval($technoloCALC[$k][1]);
eval($technoloCALC[$k][2]);
$pointstech += $a + $b + $c;
}
}
//Calcul des points du joueur
$pointstech = $plan->calculerTechnologies();
//Division par 1000
$pointstech /= 1000;
$pointsvais /= 1000;
$pointsterr /= 1000;
$pointsbat /= 1000;
//Calcul des points totaux
$points = $pointsbat + $pointsterr + $pointsvais + $pointstech;
//Mise à jour des points pour le joueur
$bdd->connexion();
$bdd->query("UPDATE $table_user SET points = $points, batiments = $pointsbat, recherches = $pointstech, flotte = $pointsvais, terrestre = $pointsterr WHERE id = $id_user;");
if ($queryUser['auth_level'] < 2 && $queryUser['mv'] < 2) $bdd->query("INSERT INTO $table_classement (id_user, points, flottes, terrestres, recherches, batiments) VALUES ($id_user, $points, $pointsvais, $pointsterr, $pointstech, $pointsbat);");
if ($queryUser['auth_level'] < 2 && $queryUser['mv'] < 2) $bdd->query("INSERT INTO $table_classement (id_user, pseudo, points, flottes, terrestres, recherches, batiments) VALUES ($id_user, '".$queryUser['pseudo']."', $points, $pointsvais, $pointsterr, $pointstech, $pointsbat);");
$bdd->deconnexion();
}
$p = 0;
$bdd->connexion();
$classement = $bdd->query("SELECT U.id, U.auth_level FROM $table_classement C INNER JOIN $table_user U ON C.id_user = U.id ORDER BY C.points DESC;");
$cnt = $bdd->num_rows;
$p = 0;
for($i = 0; $i < $cnt; $i++){
if ($classement[$i]['auth_level'] < 2) {
foreach($classement as $ligne){
if ($ligne['auth_level'] < 2) {
$p++;
$bdd->query("UPDATE $table_user SET place_points = $p WHERE id = ".$classement[$i]['id']);
$bdd->query("UPDATE $table_user SET place_points = $p WHERE id = ".$ligne['id']);
}
else $bdd->query("UPDATE $table_user SET place_points = 0 WHERE id = ".$classement[$i]['id']);
else $bdd->query("UPDATE $table_user SET place_points = 0 WHERE id = ".$ligne['id']);
}
$bdd->deconnexion();
//*/
print '<br />Fin de la génération du classement joueur ; il est : '.date('d/m/Y H:i:s');
@ -99,11 +71,11 @@ print '<br />Fin de la génération du classement joueur ; il est : '.date('d/m/
$bdd->connexion();
$bdd->query("TRUNCATE TABLE $table_classement_alliances;");
$alliances = $bdd->query("SELECT U.id_alliance, SUM(U.id) AS nombre, SUM(U.points)/SUM(U.id) AS points, SUM(U.batiments)/SUM(U.id) AS batiments, SUM(U.recherches)/SUM(U.id) AS recherches, SUM(U.flotte)/SUM(U.id) AS flotte, SUM(U.terrestre)/SUM(U.id) AS terrestre FROM $table_user U GROUP BY U.id_alliance;");
$cnt = $bdd->num_rows;
for($i = 0; $i < $cnt; $i++){
if ($alliances[$i]['id_alliance'] != 0) $bdd->query("INSERT INTO $table_classement_alliances (id_alliance, nbr_membres, points, batiments, recherches, flottes, terrestres) VALUES (".$alliances[$i]['id_alliance'].", ".$alliances[$i]['nombre'].", ".$alliances[$i]['points'].", ".$alliances[$i]['batiments'].", ".$alliances[$i]['recherches'].", ".$alliances[$i]['flotte'].", ".$alliances[$i]['terrestre'].");");
foreach($alliances as $alliance){
if ($alliance['id_alliance'] != 0) $bdd->query("INSERT INTO $table_classement_alliances (id_alliance, nbr_membres, points, batiments, recherches, flottes, terrestres) VALUES (".$alliance['id_alliance'].", ".$alliance['nombre'].", ".$alliance['points'].", ".$alliance['batiments'].", ".$alliance['recherches'].", ".$alliance['flotte'].", ".$alliance['terrestre'].");");
}
$bdd->deconnexion();
print '<br />Fin de la génération du classement ; il est : '.date('d/m/Y H:i:s');
?>

View file

@ -1,110 +1,114 @@
<?php
if(!defined('CRON')) { header('Location: ../'); exit; }
print '<br /><br />Début de la sauvegarde de la base de données ; il est : '.date('d/m/Y H:i:s');
function dumpTable($fp, $nomtable) {
global $config;
include(_FCORE."../game/tables.php");
$bdd = new bdd();
if (!function_exists('gzopen')) $fwrite = 'fwrite';
else $fwrite = 'gzwrite';
$fwrite($fp, "-- Données de la table $nomtable\n\n");
$bdd->connexion();
$nomtable = ${'table_'.$nomtable};
$res = $bdd->query('SELECT * FROM '.$nomtable.';');
$bdd->deconnexion();
for($i = 0; $i < $bdd->num_rows; $i++){
$strFieldsNames = '';
$strFieldsValues = '';
foreach ($res[$i] as $field_name => $field_value){
if ($strFieldsNames) $strFieldsNames .= ', ';
$strFieldsNames .= "$field_name";
if($strFieldsValues) $strFieldsValues .= ', ';
$strFieldsValues .= "'" . addslashes($field_value) . "'";
}
$fwrite($fp, 'INSERT INTO '.$nomtable.' ('.$strFieldsNames.') VALUES ('.$strFieldsValues.");\n");
}
$fwrite($fp, "\n\n");
}
function dumpTableXML($fp, $nomtable) {
global $config;
include(_FCORE."../game/tables.php");
$bdd = new bdd();
$bdd->connexion();
$nomtable = ${'table_'.$nomtable};
$res = $bdd->query('SELECT * FROM '.$nomtable.';');
$bdd->deconnexion();
fwrite($fp, "<table name=\"$nomtable>\"\n");
for($i = 0; $i < $bdd->num_rows; $i++){
fwrite($fp, "\t<enregistrement i=\"$i\">\n");
foreach ($res[$i] as $field_name => $field_value){
fwrite($fp, "\t\t<$field_name>".htmlentities($field_value)."</$field_name>\n");
}
fwrite($fp, "\t</enregistrement>\n");
}
fwrite($fp, "</table>\n");
}
//Création du fichier de destination
$fname = _FCORE."backup/".date('Y-m-d H-i-s');
if (true || !function_exists('gzopen')) {
$fp = fopen($fname.'.sql', 'w+');
$ext = 'sql';
$fwrite = 'fwrite';
}
if(!is_writable(_FCORE."backup/")) print 'dossier backup non accessible en ecriture ! Impossible de faire la sauvegarde de la base de données';
else {
$fp = gzopen($fname.'.gz', 'w+');
$ext = 'gz';
$fwrite = 'gzwrite';
}
$fpx = fopen($fname.'.xml', 'w+');
function dumpTable($fp, $nomtable) {
global $config;
include(_FCORE."../game/tables.php");
$bdd = new bdd();
if ($fp) {
$fwrite($fp, "-- Utilitaire de sauvegarde de base de données de HB\n-- Sauvegarde du ".date('d/m/Y H:i:s')."\n-- Version du jeu : ".$config['version']."\n\n");
fwrite($fpx, '<?xml version="1.0" encoding="UTF-8" ?>'."\n<!DOCTYPE SavBDD_HB>\n");
if (!function_exists('gzopen')) $fwrite = 'fwrite';
else $fwrite = 'gzwrite';
//Liste des tables à sauvegarder
$list = array('alliances', 'alliances_attente', 'alliances_chat', 'alliances_creation', 'alliances_grade', 'flottes', 'flottes_combats', 'planete', 'user');
$fwrite($fp, "-- Données de la table $nomtable\n\n");
$bdd->connexion();
$nomtable = ${'table_'.$nomtable};
$res = $bdd->query('SELECT * FROM '.$nomtable.';');
$bdd->deconnexion();
foreach($list as $table) {
dumpTable($fp, $table);
dumpTableXML($fpx, $table);
for($i = 0; $i < $bdd->num_rows; $i++){
$strFieldsNames = '';
$strFieldsValues = '';
foreach ($res[$i] as $field_name => $field_value){
if ($strFieldsNames) $strFieldsNames .= ', ';
$strFieldsNames .= "$field_name";
if($strFieldsValues) $strFieldsValues .= ', ';
$strFieldsValues .= "'" . addslashes($field_value) . "'";
}
$fwrite($fp, 'INSERT INTO '.$nomtable.' ('.$strFieldsNames.') VALUES ('.$strFieldsValues.");\n");
}
$fwrite($fp, "\n\n");
}
function dumpTableXML($fp, $nomtable) {
global $config;
include(_FCORE."../game/tables.php");
$bdd = new bdd();
$bdd->connexion();
$nomtable = ${'table_'.$nomtable};
$res = $bdd->query('SELECT * FROM '.$nomtable.';');
$bdd->deconnexion();
fwrite($fp, "<table name=\"$nomtable>\"\n");
for($i = 0; $i < $bdd->num_rows; $i++){
fwrite($fp, "\t<enregistrement i=\"$i\">\n");
foreach ($res[$i] as $field_name => $field_value){
fwrite($fp, "\t\t<$field_name>".htmlentities($field_value)."</$field_name>\n");
}
fwrite($fp, "\t</enregistrement>\n");
}
fwrite($fp, "</table>\n");
}
//Création du fichier de destination
$fname = _FCORE."backup/".date('Y-m-d H-i-s');
if (true || !function_exists('gzopen')) {
$fp = fopen($fname.'.sql', 'w+');
$ext = 'sql';
$fwrite = 'fwrite';
}
else {
$fp = gzopen($fname.'.gz', 'w+');
$ext = 'gz';
$fwrite = 'gzwrite';
}
$fpx = fopen($fname.'.xml', 'w+');
if ($fp) {
$fwrite($fp, "-- Utilitaire de sauvegarde de base de données de HB\n-- Sauvegarde du ".date('d/m/Y H:i:s')."\n-- Version du jeu : ".$config['version']."\n\n");
fwrite($fpx, '<?xml version="1.0" encoding="UTF-8" ?>'."\n<!DOCTYPE SavBDD_HB>\n");
//Liste des tables à sauvegarder
$list = array('alliances', 'alliances_attente', 'alliances_chat', 'alliances_creation', 'alliances_grade', 'flottes', 'flottes_combats', 'planete', 'user');
foreach($list as $table) {
dumpTable($fp, $table);
dumpTableXML($fpx, $table);
}
}
if (!function_exists('gzopen')) fclose($fp);
else gzclose($fp);
// TODO tester l'envoie de mail !!
if (@$envoyer_mail) {
require_once(_FCORE."../game/Class/class.phpmailer.php");
$mail = new PHPmailer();
$mail->SetLanguage('fr', _FCORE."../game/Class/");
$mail->IsSMTP();
$mail->Host='s-fr.com';
$mail->From='no-reply@halo-battle.s-fr.com';
$mail->FromName='Halo-Battle';
$mail->SMTPAuth=true;
$mail->Username='no-reply@halo-battle.s-fr.com';
$mail->Password='hD3e2nXu';
$mail->AddAddress('sauv@gmail.com');
$mail->AddReplyTo('no-reply@halo-battle.s-fr.com');
$mail->Subject = 'Sauvegarde du '.date('d/m/Y à H:i:s');
$mail->Body = 'Utilitaire de sauvegarde de base de données de HB version '.$config['version'];
$mail->AddAttachment($fname.'.'.$ext);
$return = $mail->Send();
$mail->SmtpClose();
}
}
if (!function_exists('gzopen')) fclose($fp);
else gzclose($fp);
// TODO tester l'envoie de mail !!
if (@$envoyer_mail) {
require_once(_FCORE."../game/Class/class.phpmailer.php");
$mail = new PHPmailer();
$mail->SetLanguage('fr', _FCORE."../game/Class/");
$mail->IsSMTP();
$mail->Host='s-fr.com';
$mail->From='no-reply@halo-battle.s-fr.com';
$mail->FromName='Halo-Battle';
$mail->SMTPAuth=true;
$mail->Username='no-reply@halo-battle.s-fr.com';
$mail->Password='hD3e2nXu';
$mail->AddAddress('sauv@gmail.com');
$mail->AddReplyTo('no-reply@halo-battle.s-fr.com');
$mail->Subject = 'Sauvegarde du '.date('d/m/Y à H:i:s');
$mail->Body = 'Utilitaire de sauvegarde de base de données de HB version '.$config['version'];
$mail->AddAttachment($fname.'.'.$ext);
$return = $mail->Send();
$mail->SmtpClose();
}
print '<br />Fin de la sauvegarde de la base de données ; il est : '.date('d/m/Y H:i:s').'<br />';
?>