Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('max_execution_time', 800);
- // This file updates EXP highscores only.
- // Other highscores are saved separatly, at diffrent times to even server load.
- include("../config.php");
- include("../library/tibiaparser.class.php");
- include("../library/mysql.db.class.php");
- function microtime_float()
- {
- list($usec, $sec) = explode(" ", microtime());
- return ((float)$usec + (float)$sec);
- }
- $time_start = microtime_float();
- // Pending
- // Last update: 2013-06-19 16:57 CEST
- // Set database object
- $updated_worlds = array();
- global $db;
- $db = new database($db_host, $db_name, $db_user, $db_pass);
- // Updates Tibia Worlds based on Tibia.com
- $tc = new TibiaDotCom();
- // First we get all worlds
- $date = date('Y-m-d');
- /*
- $db->query("SELECT name, id FROM worlds WHERE name = :name LIMIT 0,1");
- $db->bind(":name", "Olympa");*/
- $db->query("SELECT name, id FROM worlds WHERE experience_updated != :updated LIMIT 0, 8");
- $db->bind(":updated", $date);
- $worlds = $db->resultSet();
- // Update each worlds experience.
- foreach($worlds as $w){
- $worldid = $w["id"];
- $world = $w["name"];
- $updated_worlds[] = $world;
- for($i = 0; $i < 12; $i++){ // Loop through all pages for each world
- $highscore = $tc->getHighscores($world, "Experience", $i);
- foreach($highscore as $h){
- $db->query("SELECT id FROM characters WHERE name = :name");
- // Bind
- $db->bind(":name", $h["name"]);
- $check = $db->single();
- $date = date("Y-m-d");
- if(empty($check)){
- // Char doesn't exist
- $db->query("INSERT INTO characters (name, world, level, exp_updated) VALUES(:name, :world, :level, :date)");
- // Bind
- $db->bind(":name", $h["name"]);
- $db->bind(":world", $worldid);
- $db->bind(":level", $h["level"]);
- $db->bind(":date", $date);
- // Execute and get ID
- $db->execute();
- $charid = $db->lastInsertId();
- } else {
- // Char exists
- $charid = $check["id"];
- $db->query("UPDATE characters SET level = :level, exp_updated = :date WHERE name = :name");
- $db->bind(":level", $h["level"]);
- $db->bind(":name", $h["name"]);
- $db->bind(":date", $date);
- $db->execute();
- }
- // Check if character has been updated today
- $db->query("SELECT * FROM exp_history WHERE date = :date AND charid = :charid");
- $db->bind(":date", $date);
- $db->bind(":charid", $charid);
- $updated_check = $db->resultset();
- // No record for today, save the current record.
- if(count($updated_check) == 0){
- // Insert EXP record into history.
- $db->query("INSERT INTO exp_history (charid, experience, date, level) VALUES(:charid, :experience, :date, :level)");
- // Bind
- $db->bind(":charid", $charid);
- $db->bind(":level", $h["level"]);
- $db->bind(":experience", $h["value"]);
- $db->bind(":date", $date);
- // execute
- $db->execute();
- }
- }
- }
- $db->query("UPDATE worlds SET experience_updated = :date WHERE id = :id");
- $db->bind(":date", $date);
- $db->bind(":id", $worldid);
- $db->execute();
- }
- $time_end = microtime_float();
- $time = $time_end - $time_start;
- echo 'It took: '.$time.'s to update '.count($updated_worlds).' worlds.';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement