Comme tu voudras mais si tu comprends quelque chose sans connaitre toutes les fonctions et variables, je te nomme "Dieu".
Ce script est sous licence Creative Commons Paternité-Pas d'Utilisation Commerciale-Partage des Conditions Initiales à l'Identique 2.0 France:
Les requêtes SQL à la fin ne vous permettent PAS de recréer les tables utilisées mais servaient à modifier les anciennes tables afin d'être compatible avec ce système.Ce script est sous licence Creative Commons Paternité-Pas d'Utilisation Commerciale-Partage des Conditions Initiales à l'Identique 2.0 France:
Code PHP :
<?php //stats_update.php By IGstaff
/*
Fichier de mise à jour automatique sans affichage des résultat.
Les tableaux suivants doivent être définis et complétés:
- $DBTables
- $PointsTypes
*/
function countbylvl($level,$pricelist) {
$points = 0;
$points = ($pricelist["metal"]+$pricelist["crystal"]+$pricelist["deuterium"])*(1+$pricelist["factor"]*(1-pow($pricelist["factor"],$level))/(1-$pricelist["factor"]));
$points /= 1000;
return $points;
}
function countbynb($nb,$pricelist) {
$resultat = $nb*($pricelist["metal"] + $pricelist["crystal"] + $pricelist["deuterium"]);
$resultat /= 1000;
return $resultat;
}
//Mise à jour de la config
//Celle ci a été mise avant car si elle dure, elle risquerait de se répéter en cas de rechargement de la page.
$time = ( defined("TIME") ) ? TIME : time();
doquery("UPDATE {{table}} SET config_value={$time} WHERE config_name='stats' ","config");
$DBTablesF = array_big_flip($DBTables);
$Universe = $Points = $Ranks = array();
foreach($DBTables["BinSyst"] AS $BinSystTableName) {
$AllBinSystSQL = doquery("SELECT * FROM {{table}}", $BinSystTableName);
while( $AllBinSystArr = mysql_fetch_assoc($AllBinSystSQL) ) {
$Universe[$AllBinSystArr["id_owner"]][$BinSystTableName][$AllBinSystArr["id"]] = $AllBinSystArr;
}
}
text("Mise à jour des points !");
$AllUsersSQL = doquery("SELECT * FROM {{table}}","users");
while( $AllUsersArr = mysql_fetch_assoc($AllUsersSQL) ) {
$UserID = $AllUsersArr["id"];
if( !empty($Universe[$UserID]) ) { //Si le joueur a des planètes/lunes
//Initialisation des points
$points = array();
$Universe[$UserID][$DBTables["User"]] = $AllUsersArr;
$UserArr = $Universe[$UserID];
unset($AllUsersArr);
//Enregistrement des points actuels comme anciens.
foreach($PointsTypes["User"] as $PointsTypeName) {
$UserArr[$DBTables["User"]]["points_{$PointsTypeName}_old"] = $UserArr[$DBTables["User"]]["points_{$PointsTypeName}_cur"];
}
///Initialisation des points actuels à 0.
foreach($DBTablesF as $DBTableName => $DBTablesObj) {
if( !empty($UserArr[$DBTableName]) ) {
if( is_array($DBTables[$DBTablesObj]) ) {
foreach($UserArr[$DBTableName] as &$UserObjArr) {
foreach($PointsTypes[$DBTablesObj] as $PointsTypeName) {
$UserObjArr["points_{$PointsTypeName}_cur"] = 0;
}
}
} else {
foreach($PointsTypes[$DBTablesObj] as $PointsTypeName) {
$UserArr[$DBTableName]["points_{$PointsTypeName}_cur"] = 0;
}
}
}
}
//On liste les différents objets du système binaire (planète et lune)
foreach($DBTables["BinSyst"] AS $BinSystTableID => $BinSystTableName) {
if( !empty($UserArr[$BinSystTableName]) ) {
$UserBinSyst = $UserArr[$BinSystTableName];
foreach($UserBinSyst as &$PlanetArr) { //Boucle des planetes - Début
//Ajout des points de Batiments
foreach($reslist[$BinSystTableID]["build"] as $a) {
$level = $PlanetArr[$resource[$a]];
if( !empty($level) && $level >0 ) {
$PlanetArr["points_bui_cur"] += countbylvl($level,$pricelist[$a]);
}
}
$PlanetFleetsFlying = array();
$PlanetFleetsSQL = doquery("SELECT fleet_array FROM {{table}} WHERE fleet_start_galaxy={$PlanetArr["galaxy"]} AND fleet_start_system={$PlanetArr["system"]} AND fleet_start_planet={$PlanetArr["planet"]}", "fleets");
while( $PlanetFleetsArr = mysql_fetch_assoc($PlanetFleetsSQL) ) {
$PlanetFleetsFlying = array_add_values($PlanetFleetsFlying, strtoarr($PlanetFleetsArr["fleet_array"]));
}
foreach($reslist[$BinSystTableID]["fleet"] as $a) { //Ajout des points de Flotte
$nb = $PlanetArr[$resource[$a]] + ( ( empty($PlanetFleetsFlying[$a]) ) ? 0 : $PlanetFleetsFlying[$a] );
if( !empty($nb) && $nb >0 ) {
$PlanetArr["points_fle_cur"] += countbynb($nb, $pricelist[$a]);
}
}
foreach($reslist[$BinSystTableID]["defense"] as $a) { //Ajout des points de Défense
$nb = $PlanetArr[$resource[$a]];
if( !empty($nb) && $nb >0 ) {
$PlanetArr["points_def_cur"] += countbynb($nb, $pricelist[$a]);
}
}
//Ajout dans les points totaux de l'utilisateur
$UserArr[$DBTables["User"]]["points_bui_cur"] += $PlanetArr["points_bui_cur"];
$UserArr[$DBTables["User"]]["points_fle_cur"] += $PlanetArr["points_fle_cur"];
$UserArr[$DBTables["User"]]["points_def_cur"] += $PlanetArr["points_def_cur"];
//Enregistrement dans la base SQL - Planète
doquery("UPDATE {{table}} SET points_bui_cur={$PlanetArr["points_bui_cur"]}, points_fle_cur={$PlanetArr["points_fle_cur"]},
points_def_cur={$PlanetArr["points_def_cur"]} WHERE id={$PlanetArr["id"]} LIMIT 1", $type_tab[$BinSystTableID]);
}
}
}
foreach($reslist[0]["tech"] as $a) { //Ajout des points de Technologies
$level = $UserArr[$DBTables["User"]][$resource[$a]];
if(!empty($level) && $level >0) {
$UserArr[$DBTables["User"]]["points_sea_cur"] += countbylvl($level,$pricelist[$a]);
}
}
if( !$UserArr[$DBTables["User"]]["authlevel"] || !empty($game_config["admin_instats"]) ) { //On exclue les admin du classement.
$Points["total"][$UserID] = $UserArr[$DBTables["User"]]["points_sea_cur"] + $UserArr[$DBTables["User"]]["points_bui_cur"]
+ $UserArr[$DBTables["User"]]["points_fle_cur"] + $UserArr[$DBTables["User"]]["points_def_cur"];
$Points["sea"][$UserID] = $UserArr[$DBTables["User"]]["points_sea_cur"];
$Points["bui"][$UserID] = $UserArr[$DBTables["User"]]["points_bui_cur"];
$Points["fle"][$UserID] = $UserArr[$DBTables["User"]]["points_fle_cur"];
$Points["def"][$UserID] = $UserArr[$DBTables["User"]]["points_def_cur"];
}
$Universe[$UserID] = $UserArr;
}
}
unset($UserArr);
$Points = array_map("re_arsort", $Points);
foreach($Points as $PointType => $PointUsers) {
$Rank = 0;
foreach($PointUsers as $PointUserID => $PointUserNb) {
$Rank++;
$Ranks[$PointUserID][$PointType] = $Rank;
}
}
foreach($Ranks as $RankUserID => $RankTypes) {
$UserQuery = "";
foreach($RankTypes as $RankType => $RankNb) {
$UserQuery .= var_add($UserQuery, ",")."`points_{$RankType}_old`=points_{$RankType}_cur, `points_{$RankType}_cur`={$Points[$RankType][$RankUserID]},
`rank_{$RankType}_old`=rank_{$RankType}_cur, `rank_{$RankType}_cur`={$RankNb}";
}
doquery("UPDATE {{table}} SET {$UserQuery} WHERE `id`={$RankUserID} ", "users");
}
//Suppression du cache des statistiques
cache_delete_all("stats");
/* 04/11/08
ALTER TABLE `ugml_users` DROP `rank`,
DROP `rank_old`,
CHANGE `points_sea` `points_sea_cur` BIGINT( 15 ) UNSIGNED NOT NULL DEFAULT '0',
CHANGE `points_bui` `points_bui_cur` BIGINT( 15 ) UNSIGNED NOT NULL DEFAULT '0',
CHANGE `points_fle` `points_fle_cur` BIGINT( 15 ) UNSIGNED NOT NULL DEFAULT '0',
CHANGE `points_def` `points_def_cur` BIGINT( 15 ) UNSIGNED NOT NULL DEFAULT '0',
ADD `points_total_cur` BIGINT( 15 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `deleteaccount`,
ADD `points_total_old` BIGINT( 15 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `points_def_cur`,
ADD `total_rank_cur` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `points_def_old` ,
ADD `sea_rank_cur` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `total_rank_cur` ,
ADD `bui_rank_cur` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `sea_rank_cur` ,
ADD `fle_rank_cur` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `bui_rank_cur` ,
ADD `def_rank_cur` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `fle_rank_cur` ,
ADD `total_rank_old` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `def_rank_cur` ,
ADD `sea_rank_old` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `total_rank_old` ,
ADD `bui_rank_old` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `sea_rank_old` ,
ADD `fle_rank_old` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `bui_rank_old` ,
ADD `def_rank_old` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `fle_rank_old` ;
ALTER TABLE `ugml_planets`
DROP `points_bui_old`,
DROP `points_fle_old`,
DROP `points_def_old`,
CHANGE `points_bui` `points_bui_cur` BIGINT( 15 ) UNSIGNED NOT NULL DEFAULT '0',
CHANGE `points_fle` `points_fle_cur` BIGINT( 15 ) UNSIGNED NOT NULL DEFAULT '0',
CHANGE `points_def` `points_def_cur` BIGINT( 15 ) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `ugml_lunas`
DROP `points_bui_old`,
DROP `points_fle_old`,
DROP `points_def_old`,
CHANGE `points_bui` `points_bui_cur` BIGINT( 15 ) UNSIGNED NOT NULL DEFAULT '0',
CHANGE `points_fle` `points_fle_cur` BIGINT( 15 ) UNSIGNED NOT NULL DEFAULT '0',
CHANGE `points_def` `points_def_cur` BIGINT( 15 ) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `ugml_users` CHANGE `total_rank_cur` `rank_total_cur` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0',
CHANGE `sea_rank_cur` `rank_sea_cur` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0',
CHANGE `bui_rank_cur` `rank_bui_cur` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0',
CHANGE `fle_rank_cur` `rank_fle_cur` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0',
CHANGE `def_rank_cur` `rank_def_cur` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0',
CHANGE `total_rank_old` `rank_total_old` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0',
CHANGE `sea_rank_old` `rank_sea_old` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0',
CHANGE `bui_rank_old` `rank_bui_old` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0',
CHANGE `fle_rank_old` `rank_fle_old` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0',
CHANGE `def_rank_old` `rank_def_old` INT( 5 ) UNSIGNED NOT NULL DEFAULT '0';
*/
?>
Elles peuvent vous aider à comprendre le script cependant.