Fwaky

Untitled

Dec 25th, 2015
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.10 KB | None | 0 0
  1. <?php
  2. ini_set('max_execution_time', 6000);
  3. // This file updates EXP highscores only.
  4. // Other highscores are saved separatly, at diffrent times to even server load.
  5. include("../config.php");
  6. include("../library/tibiaparser.class.php");
  7. include("../library/mysql.db.class.php");
  8. $updated_worlds = array();
  9. // Pending
  10. // Last update: 2013-06-19 18:03 CEST
  11. // Set database object
  12. global $db;
  13. $db = new database($db_host, $db_name, $db_user, $db_pass);
  14. // Updates Tibia Worlds based on Tibia.com
  15. $tc = new TibiaDotCom();
  16.  
  17. // First we get all worlds
  18.     $date = date("Y-m-d");
  19.     $db->query("SELECT name, id FROM worlds WHERE skills_updated != :updated LIMIT 0,5");
  20.     $db->bind(":updated", $date);
  21.     $worlds = $db->resultSet();
  22.     $skills = array("magic", "shielding", "distance", "sword", "club", "axe", "fist", "fishing", "achievements");
  23.     foreach($worlds as $w){
  24.         $worldid = $w["id"];
  25.         $world   = $w["name"];
  26.         $updated_worlds[] = $world;
  27.         foreach($skills as  $s){
  28.             for($i = 0; $i < 12; $i++){
  29.                 $highscore = $tc->getHighscores($world, $s, $i);
  30.                 foreach($highscore as $h){
  31.                     $db->query("SELECT id FROM characters WHERE name = :name");
  32.                         // Bind
  33.                         $db->bind(":name", $h["name"]);
  34.                     $check = $db->single();
  35.                     if(empty($check)){
  36.                         // Char doesn't exist
  37.                         $db->query("INSERT INTO characters (name, world) VALUES(:name, :world)");
  38.                             // Bind
  39.                             $db->bind(":name", $h["name"]);
  40.                             $db->bind(":world", $worldid);
  41.                         // Execute and get ID
  42.                         $db->execute();
  43.                         $charid = $db->lastInsertId();
  44.                     } else {
  45.                         // Char exists
  46.                         $charid = $check["id"];
  47.                     }
  48.                     // Insert EXP record into history.
  49.                     $db->query("UPDATE characters SET ".$s." = :skill WHERE id = :charid");
  50.                         // Bind
  51.                         $db->bind(":charid", $charid);
  52.                         $db->bind(":skill", $h["value"]);
  53.  
  54.                     // execute
  55.                     $db->execute();
  56.                 }
  57.                 set_time_limit(60);
  58.             }
  59.         }
  60.         $db->query("UPDATE worlds SET skills_updated = :date WHERE id = :id");
  61.         $db->bind(":date", $date);
  62.         $db->bind(":id", $worldid);
  63.         $db->execute();
  64.     }
  65.  
  66. unset($db);
  67. print_r($updated_worlds);
  68. ?>
Add Comment
Please, Sign In to add comment