Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- #script
- //Raport de bug
- function bug($message)
- {
- $message = heure(time()).' : '.$message;
- $message .= @file_get_contents('Templates/cache/bugs.txt');
- file_put_contents('Templates/cache/bugs.txt', $message);
- }
- function getIdParrain($idUser){
- return (floor(($idUser*61)/42)+182).$idUser;
- }
- function getQueryResults($sql, $params = null, $style = PDO::FETCH_ASSOC)
- {
- count_requete($requete);
- global $bdd, $sql_error;
- try
- {
- $req = $bdd->prepare($sql);
- $req->execute($params);
- $res = $req->fetchAll($style);
- $sql_error = null;
- } catch (PDOException $e)
- {
- $res = [];
- $sql_error = $e->getCode();
- }
- return $res;
- }
- function is_mod_activated($idModule, $player){
- $playerPsd = htmlspecialchars($player);
- return (getQueryResults('SELECT COUNT(ID) AS mod_installed FROM modules_joueurs WHERE pseudo = ? && id_module = ? && base_link = 1', [$playerPsd,$idModule])[0]['mod_installed']) == 1;
- }
- function getModParam($idModule, $option, $player){
- $playerPsd = htmlspecialchars($player);
- $config = getQueryResults('SELECT config FROM modules_joueurs WHERE pseudo = ? && id_module = ?', [$playerPsd, $idModule])[0]['config'];
- $out = explode(';',$config);
- foreach($out as $val){
- $data = explode('=',$val);
- if($data[0] == $option){
- return $data[1];
- }
- }
- return false;
- }
- function returnAllParam($idModule, $player){
- $playerPsd = htmlspecialchars($player);
- $config = getQueryResults('SELECT config FROM modules_joueurs WHERE pseudo = ? AND id_module = ?', [$playerPsd, $idModule])[0]['config'];
- $sortie_info = explode(';',$config);
- return $sortie_info;
- }
- function modifParamMod($idModule, $option, $newval, $player){
- $playerPsd = htmlspecialchars($player);
- $oldConfig = getQueryResults('SELECT config FROM modules_joueurs WHERE pseudo = ? AND id_module = ?', [$playerPsd, $idModule])[0]['config'];
- $oldParam = getModParam($idModule, $option, $player);
- $newConfig = str_replace($option.'='.$oldParam, $option.'='.$newval, $oldConfig);
- return getQueryResults('UPDATE modules_joueurs SET config = ? WHERE pseudo = ? AND id_module = ?',[$newConfig, $playerPsd, $idModule]);
- }
- function sql_query($requete)
- {
- count_requete($requete);
- require('log_bdd.php');
- try {
- $bddW = new PDO($dsnW, $userW, $passwordW);
- $bddW->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- } catch (PDOException $e) {
- die('Echec de la connexion : ' . $e->getMessage());
- }
- return @$bddW->query($requete);
- }
- function count_requete($requete)
- {
- static $nb_requete = 0;
- $nb_requete++;
- return $nb_requete;
- }
- function dateDiff($date1, $date2){
- $diff = abs($date1 - $date2); // abs pour avoir la valeur absolute, ainsi éviter d'avoir une différence négative
- $retour = array();
- $tmp = $diff;
- $retour['second'] = $tmp % 60;
- $tmp = floor( ($tmp - $retour['second']) /60 );
- $retour['minute'] = $tmp % 60;
- $tmp = floor( ($tmp - $retour['minute'])/60 );
- $retour['hour'] = $tmp % 24;
- $tmp = floor( ($tmp - $retour['hour']) /24 );
- $retour['day'] = $tmp;
- return $retour;
- }
- function updateXpAlliances(){
- $alliList = getQueryResults('SELECT id FROM alliances');
- $isMe = false;
- foreach ($alliList as $alli) {
- $xpMemberList = getQueryResults('SELECT xp, psd FROM users WHERE alliance = ?', [$alli['id']]);
- $sumXp = 0;
- foreach ($xpMemberList as $unicval) {
- $sumXp+=$unicval['xp'];
- if($unicval['psd'] == $_SESSION['psd']){
- $isMe = true;
- }
- }
- if($isMe === true){ //update session variable
- $_SESSION['xp_ally'] = $sumXp;
- $isMe = false;
- }
- getQueryResults('UPDATE alliances SET xp = ? WHERE id = ?', [$sumXp, $alli['id']]);
- }
- }
- //heure - date
- function heure($time)
- {
- return date('\l\e d/m à H:i', $time);
- }
- function heure_light($time)
- {
- return date('d/m à H\h', $time);
- }
- //Redirection header
- function redirection($addr)
- {
- header('location: '.$addr);
- }
- function maj_attdef_pl(){ /*Update planets static stats*/
- $infosJ = explode(' ', return_cache('cache_'.$_SESSION['psd'].'.cache'));
- $frcJ = round($infosJ[1]/2,0);
- sql_query('UPDATE planetes SET att = clones+age/2, def = clones+age/2, portee = 5+(age/16), prod = 10*age-(clones/(age*2)) + 50');
- }
- //File get contents
- function get_file($file)
- {
- if(is_file($file))
- return file_get_contents($file);
- else
- return bug('Le fichier '.$file.' est introuvable.
- ');
- }
- function prix2($org) /*Return unity prices with the selected organization*/
- {
- $prix = Array('soldats' => 10, 'chevaliers' => 80, 'archers' => 80, 'heros' => 200);
- /*if($org == 5)
- $prix['soldats'] = 3;*/
- return $prix;
- }
- function statsAtq($org) /*Return attack stats with the selected organization*/
- {
- $statsAtq = Array('soldats' => 1, 'chevaliers' => 15, 'archers' => 30, 'heros' => 100);
- if($org == 2)
- $statsAtq['archers'] = 50;
- elseif($org == 4)
- $statsAtq['heros'] = 130;
- elseif($org == 5)
- $statsAtq['soldats'] = 2;
- return $statsAtq;
- }
- function statsDef($org) /*Return defense stats with the selected organization*/
- {
- $statsDef = Array('soldats' => 1, 'chevaliers' => 30, 'archers' => 15, 'heros' => 100);
- if($org == 1)
- $statsDef['chevaliers'] = 45;
- elseif($org == 4)
- $statsDef['heros'] = 130;
- return $statsDef;
- }
- function unites($org) /*Return unities with the selected organization*/
- {
- $unites = Array('Clones', 'Droïdes', 'Padawans', 'Jedis');
- if($org == 1)
- $unites[1] = 'Siths';
- elseif($org == 2)
- $unites[2] = 'Wookies';
- elseif($org == 4)
- $unites[3] = 'Zabraks';
- elseif($org == 5)
- $unites[0] = 'Eworks';
- return $unites;
- }
- function verify_avatar($avatar)
- {
- //$infosavatar = @getimagesize($avatar);
- //if($infosavatar[0] > 50 OR $infosavatar[1] >50 OR $infosavatar[2] > 3)
- //return false;
- //else
- //if(@fopen($avatar, 'r' ))
- return true;
- }
- function nombre_format($nombre) /*Better display of huge numbers*/
- {
- if(strpos($_SERVER["HTTP_USER_AGENT"], 'Firefox') !== false){
- return $nombre;
- }else{
- $nombre=number_format($nombre, 0, ',', ' ');
- return $nombre;
- }
- }
- function safest($var)
- {
- $var = htmlentities($var, ENT_QUOTES);
- return $var;
- }
- function chatConnectes() /*Return the list of users online*/
- {
- $timestampCinqMinutes = time()-(60*5); // timestamp qu'il sera dans 5 minutes
- $dir = './Templates/cache/chat/';
- $fichierConnectes = glob($dir.'*.tmp'); // Récupération des fichiers temporaires déjà présents
- $nbConnectes = 0; // Déclaration de la variable qui contiendra le nombre de connectés
- if($_SESSION['psd'] AND is_file($dir.$_SESSION['psd'].'.tmp')) // Si le visiteur est déjà connecté
- {
- touch($dir.$_SESSION['psd'].'.tmp'); // On modifie la date de dernière modification du fichier
- }
- elseif($_SESSION['psd']) // Sinon
- {
- $fichierVisiteur = fopen($dir.$_SESSION['psd'].'.tmp', 'x+'); // On crée un nouveau fichier
- fclose($fichierVisiteur);
- }
- $fichiersConnectes = glob($dir.'*.tmp'); // On renouvelle la liste des fichiers temporaires
- foreach($fichiersConnectes AS $fichier)
- {
- if(filemtime($fichier) >= $timestampCinqMinutes) $nbConnectes++; // Si le fichier a été modifié dans les 5 dernières minutes, on incrémente $nbConnectes
- else unlink($fichier); // Sinon on le supprime
- }
- return $nbConnectes;
- }
- function utfdecode($machaine)
- {
- $machaine=($machaine);
- $carracterasoucis = Array("ç","ä§","é","ä©","è","ä¨","ê",
- "äª","ë","ä«","Ê","äŠ","Ë","ä‹","î","ä®","ï","ä¯","ì"
- ,"Ã?","ä?","ò","ä²","ô","ä´","ö","ä¶","õ","ó","ø",
- "äµ","ä³","ä¸","Ô","ä”","Ö","ä–","Ã","ä","â","ä¢","ä",
- "ä¤","Ã¥","ä¥","Â","ä‚","Ä","ä„","ù","û","ü","ä¼","Û"
- ,"Ãœ","ä¹","ä»","ä¼","ä¼","ä›","äœ","ò","ñ","’");
- $topcool = Array("ç", "ç", "é", "é", "è", "è", "ê", "ê", "ë", "ë", "Ê", "Ê",
- "Ë", "Ë", "î", "î", "ï", "ï", "ì", "Î", "Î", "ò", "ò", "ô", "ô", "ö", "ö", "õ",
- "ó", "ø", "õ", "ó", "ø", "Ô", "Ô", "Ö", "Ö", "à", "à", "â", "â", "ä", "ä", "å",
- "å", "Â", "Â", "Ä", "Ä", "u", "û", "ü", "ü", "Û", "Ü", "u", "û", "ü", "ü", "Û",
- "Ü", "ñ", "ñ", "'");
- foreach($carracterasoucis as $key => $value)
- $machaine = str_replace($carractereasoucis[$key], $topcool[$key], $machaine);
- return $machaine;
- }
- function isconnect() /*Test a user to see if he's online*/
- {
- sql();
- $requete = sql_query('SELECT id
- FROM users
- WHERE users.psd = "'.$_SESSION['psd'].'" && users.mdp = "'.$_SESSION['mdp'].'" LIMIT 1');
- $pseudo = str_replace(' ', '', $_SESSION['psd']);
- if(!$_SESSION['log'] OR empty($pseudo) OR !$requete->rowCount())
- {
- remove_cache('cache_'.$_SESSION['psd'].'.cache');
- session_destroy();
- return header('location: index.php?ok=e');
- return exit();
- }
- else
- {
- return true;
- }
- }
- function isadmin($pseudo)
- {
- global $admin;// Voir conf.php
- $i = 0;
- foreach($admin as $key=>$value)
- {
- if($value == $pseudo)
- $i = 1;
- }
- return $i;
- }
- function ismodo($pseudo)
- {
- global $modo;// Voir conf.php
- $i = 0;
- foreach($modo as $key=>$value)
- {
- if($value == $pseudo)
- $i = 1;
- }
- return $i;
- }
- function ispremium($pseudo)
- {
- global $premium;// Voir conf.php
- $i = 0;
- foreach($premium as $key=>$value)
- {
- if($value == $pseudo)
- $i = 1;
- }
- return $i;
- }
- function isboss($pseudo)
- {
- global $boss;// Voir conf.php
- $i = 0;
- foreach($boss as $key=>$value)
- {
- if($value == $pseudo)
- $i = 1;
- }
- return $i;
- }
- function sql()
- {
- }
- # Calculs#
- function production($lv)
- {
- $or = floor($lv*$lv*40/9)*5;
- return $or;
- }
- function prix($lv)
- {
- $lv ++;
- $or = floor(($lv * $lv * $lv)/10);
- return $or;
- }
- function xp($lv)
- {
- $xp = ($lv >= 10)? ($lv-9) * 20 : -1;
- return $xp;
- }
- function lv($xp)
- {
- $lv = floor($xp-1 / 20);
- return $lv;
- }
- function limite_xp($xp)
- {
- return 50+round($xp/30);
- }
- function limite_xp_ally($xp)
- {
- return 300+round($xp/300);
- }
- function total_sacrifice($xp)
- {
- return round($xp*$xp/2+1);
- }
- function total_victoires($xp)
- {
- return round($xp/40+10);
- }
- function maj_mine($user) //update this function every hour
- {
- include('pdo.php');
- $user = htmlentities($user);
- $info_user = explode(' ', return_cache('cache_'.$user.'.cache'));
- $requete = sql_query('SELECT `timestamp`, `mine`, `ci`, banque, `etat`, `date_connexion`, `date`
- FROM users WHERE psd = "'.$user.'"');
- $donnees = $requete->fetch(PDO::FETCH_ASSOC);
- $timestamp = $donnees['timestamp'];
- if($timestamp == 0)
- sql_query('UPDATE `users` SET `timestamp` = "'.time().'" WHERE psd = "'.$user.'" LIMIT 1');
- elseif(floor((time()+1)/3600) - floor($timestamp/3600) > 0)
- {
- sql_query('UPDATE `users` SET `timestamp` = "'.time().'" WHERE psd = "'.$user.'" LIMIT 1');
- $mine = $donnees['mine'];
- $user_ci = $donnees['ci'];
- $banque = $donnees['banque'];
- $etat = $donnees['etat'];
- $date_connexion = $donnees['date_connexion'];
- $date = $donnees['date'];
- $veille = "";
- $vacances = "";
- $retourdumode = time()+(3600*7*24);
- if(!empty($date) AND $date <= time())
- {
- $date = "";
- $etat = 0;
- if($etat == '3')
- $veille = $retourdumode;
- else
- $vacances = $retourdumode;
- }
- elseif(!empty($donnees['veille']) AND $donnees['veille']<= time())
- sql_query('UPDATE users SET veille="" WHERE psd = "'.$donnees['psd'].'"');
- $timeInnactif = time()-(60*60*24*7*2);
- $timeMort = time()-(60*60*24*7*6);
- if($etat == '0' AND $date_connexion < $timeInnactif)
- $etat = 1;
- if($etat == '1' AND $date_connexion < $timeMort AND !isboss($donnees['psd']))
- $etat = 6;
- if(($etat == '6' OR $etat == '1') AND $date_connexion > $timeMort)
- $etat = 0;
- $production_ci = production($mine);
- if($etat == '3'){ //en veille
- $production_ci = round($production_ci/2);
- }elseif($etat == '4'){ //en vacances
- $production_ci = round($production_ci/5);
- }elseif($etat == '6'){
- $production_ci = 0;
- }
- if($user_ci < 0){
- $nouveau_or = $production_ci;
- }else{
- $nouveau_or = $user_ci + $production_ci*(floor(time()/3600) - floor($timestamp/3600));
- }
- sql_query('UPDATE `users` SET `ci` = "'.$nouveau_or.'", banque = "'.$banque.'", `timestamp` = "'.time().'", cible = 0, attaque = 0, etat = "'.$etat.'", veille = "'.$veille.'", vacances = "'.$vacances.'", date = "'.$date.'" WHERE psd = "'.$user.'" LIMIT 1');
- }
- return $or;
- }
- function sendMessageJournal($title, $text, $type, $user){ //send a notification to the journal of the selected user (use notifications V2)
- switch ($type) {
- case 'info':
- $icon = 'info.png';
- $alt = 'INFO';
- break;
- case 'notif':
- $icon = 'ring.jpg';
- $alt = 'NOTIFICATION';
- break;
- default:
- $icon = 'info.png';
- $alt = 'INFO';
- break;
- }
- $journal = return_cache('Journal_'.$user.'.cache');
- $idNotif = rand(1,100000);
- $message = '<tr>
- <td>'.date('j/m').' - '.date('H:i:s').' <br /><img src="Template/images/'.$icon.'" alt="'.$alt.'" height="20px" width="20px"/></td>
- <td class="txt" onclick="openNotif('.$idNotif .');">
- <b>'.$title.'</b><td class="openNotif"><a href="_CLEARNOTIF_"><img src="Template/images/bin.png" height="15px" width="15px"/></a></td>
- </td>
- </tr>
- <tr class="notifoff" id="notif'.$idNotif .'" style="display:none;">
- <td colspan="3">
- '.$text.'
- </td>
- </tr>|||';
- remove_cache('Journal_'.$user.'.cache');
- create_cache($message.$journal, 'Journal_'.$user.'.cache');
- }
- function sendMessageAlliance($msg, $alliance, $player){ /* Send message as "info" one the selected alliance (in the chat)*/
- sql_query('INSERT INTO chat_alliances (idalliance, psd, msg, date)
- VALUES ("'.$alliance.'", "-Info", "'.htmlspecialchars($msg).'", "'.time().'");');
- }
- function sendNotif($matches){ /*Send notif when people are mentionned (chat and forum)*/
- session_start();
- $psd = $_SESSION['psd'];
- $queryStr = '';
- if(preg_match("#add.php#i", $_SERVER['SCRIPT_FILENAME'])){
- $typeRequest = 'chat';
- }elseif (preg_match("#forum.php#i", $_SERVER['SCRIPT_FILENAME'])) {
- $typeRequest = 'forum';
- $queryStr = $_SERVER['QUERY_STRING'];
- }else{
- $typeRequest = '???';
- }
- $result = getQueryResults('SELECT COUNT(ID) AS NB, psd FROM users WHERE psd = ?', [$matches[1]])[0];
- $userExists = $result['NB'] == 1 ? true: false;
- $psdUser = $result['psd'];
- if($matches[1] == 'everyone' AND (isadmin($psd) OR ismodo($psd) ) ){ //global broadcast
- $getListUsers = getQueryResults('SELECT psd FROM users');
- foreach ($getListUsers as $unicUser) {
- sendMessageJournal('Notification','Vous avez été notifié dans le '.$typeRequest.' par '.$psd.'<br /><a href="'.$typeRequest.'.php?'.$queryStr.'">Voir le '.$typeRequest.'</a>.', 'notif', $unicUser['psd']);
- }
- return ($typeRequest == 'forum') ? '<gras>@everyone</gras>' : '<b>@everyone</b>';
- }elseif ($matches[1] == 'online' AND (isadmin($psd) OR ismodo($psd) )) {
- //detection des membres en ligne, voir connectes.php
- $i = 0;
- $dir = './Templates/cache/';
- $fichiersConnectes = glob($dir.'compteur/*.tmp');
- $ajout_sql = '';
- foreach($fichiersConnectes AS $fichier){
- $pseudo = ucfirst(substr(basename($fichier), 0, -4));
- if ($i == 0){
- $ajout_sql .= ' psd = "'.$pseudo.'"';
- }else{
- $ajout_sql .= ' OR psd="'.$pseudo.'"';
- }
- $i++;
- }
- if ($ajout_sql == ""){
- $ajout_sql = '1=2';
- }
- $i = 0;
- $requete = sql_query('SELECT psd FROM users WHERE '.$ajout_sql);
- while ($donnees = $requete->fetch(PDO::FETCH_ASSOC)){
- sendMessageJournal('Notification','Vous avez été notifié dans le '.$typeRequest.' par '.$psd.'<br /><a href="'.$typeRequest.'.php?'.$queryStr.'">Voir le '.$typeRequest.'</a>.', 'notif', $donnees['psd']);
- }
- return ($typeRequest == 'forum') ? '<gras>@online</gras>' : '<b>@online</b>';
- }
- if($userExists){
- sendMessageJournal('Notification','Vous avez été notifié dans le '.$typeRequest.' par '.$psd.'<br /><a href="'.$typeRequest.'.php?'.$queryStr.'">Voir le '.$typeRequest.'</a>.', 'notif', $psdUser);
- return ($typeRequest == 'forum') ? '@<lien url="joueur.php?psd='.$psdUser.'">'.$psdUser.'</lien>' : '@<a href="joueur.php?psd='.$psdUser.'">'.$psdUser.'</a>';
- }else{
- return '@'.$matches[1];
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement