Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- error_reporting(E_ALL);
- $servername = "localhost";
- $username = "ss13";
- $password = "ss13";
- $dbname = "crawl";
- $races = array(
- array("Centaur", "Ce"),
- array("Deep Dwarf", "DD"),
- array("Deep Elf", "DE"),
- array("Demigod", "Dg"),
- array("Demonspawn", "Ds"),
- array("Draconian", "Dr"),
- array("Felid", "Fe"),
- array("Formicid", "Fo"),
- array("Gargoyle", "Gr"),
- array("Ghoul", "Gh"),
- array("Halfling", "Ha"),
- array("High Elf", "HE"),
- array("Hill Orc", "HO"),
- array("Human", "Hu"),
- array("Kobold", "Ko"),
- array("Merfolk", "Mf"),
- array("Minotaur", "Mi"),
- array("Mummy", "Mu"),
- array("Naga", "Na"),
- array("Octopode", "Op"),
- array("Ogre", "Og"),
- array("Spriggan", "Sp"),
- array("Tengu", "Te"),
- array("Troll", "Tr"),
- array("Vampire, Vp"),
- array("Vine Stalker", "VS")
- );
- $classes = array(array("Fighter" ,"Fi"),
- array("Gladiator" ,"Gl"),
- array("Monk" ,"Mo") ,
- array("Hunter" ,"Hu"),
- array("Assassin" ,"As"),
- array("Berserker" ,"Be"),
- array("Abyssal Knight" ,"AK"),
- array("Chaos Knight" ,"CK"),
- array("Skald" ,"Sk"),
- array("Enchanter" ,"En"),
- array("Transmuter" ,"Tm"),
- array("Arcane Marksman" ,"AM"),
- array("Warper" ,"Wr"),
- array("Wizard" ,"Wz"),
- array("Conjurer" ,"Cj"),
- array("Summoner" ,"Su"),
- array("Necromancer" ,"Ne"),
- array("Fire Elementalist" ,"FE"),
- array("Ice Elementalist" ,"IE"),
- array("Air Elementalist" ,"AE"),
- array("Earth Elementalist" ,"EE"),
- array("Venom Mage" ,"VM"),
- array("Artificer" ,"Ar"),
- array("Wanderer" ,"Wn"));
- $gods = array(
- "Ashenzari",
- "Beogh",
- "Cheibriados",
- "Dithmenos",
- "Elyvilon",
- "Fedhas Madash",
- "Gozag Ym Sagoz",
- "Jiyva",
- "Kikubaaqudgha",
- "Lugonu",
- "Makhleb",
- "Nemelex Xobeh",
- "Okawaru",
- "Qazlal",
- "Ru",
- "Sif Muna",
- "The Shining One",
- "Trog",
- "Vehumet",
- "Xom",
- "Yredelemnul",
- "Zin"
- );
- // Create connection
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- //Get all players in the morgue
- $path = "/home/crawl/DGL/dgldir/morgue/";
- $dirs = array();
- $results = scandir($path);
- foreach ($results as $result){
- if($result === '.' or $result === '..') continue;
- if(is_dir($path . '/' . $result)){
- $dirs[] = $result;
- }
- }
- foreach($dirs as $player){
- $path = "/home/crawl/DGL/dgldir/morgue/" . $player;
- $files = array();
- $results = scandir($path);
- foreach ($results as $result){
- if($result === '.' or $result === '..') continue;
- if(is_file($path . '/' . $result)){
- $files[] = $result;
- }
- }
- $morgue = array();
- foreach($files as $file){
- $end = substr($file,-3,3);
- if($end == "txt" && $file != "$player.txt" && substr($file,0,5) != "crash"){
- $morgue[] = $file;
- }
- }
- $player_morgue = $player . "_morgue";
- //check to make tables
- $val = mysqli_query($conn, "select 1 from `$player_morgue` LIMIT 1");
- if($val !== FALSE)
- {
- continue;
- }
- else
- {
- $sql = "CREATE TABLE $player_morgue LIKE crawl_morgue";
- mysqli_query($conn, $sql);
- }
- $val = mysqli_query($conn, "select 1 from `$player` LIMIT 1");
- if($val !== FALSE)
- {
- continue;
- }
- else
- {
- $sql = "CREATE TABLE $player LIKE crawl_player";
- mysqli_query($conn, $sql);
- }
- foreach($morgue as $file){
- $myfile = fopen($path . "/$file", "r");
- $stats = fread($myfile,filesize($path . "/$file")); //open a file containing user info for security purposes it is not hard coded
- $lines = file("http://www.jorgrun.rocks/morgue/$player/$file");//file in to an array
- fclose($myfile);
- $result = mysqli_query($conn, "SELECT * FROM $player_morgue WHERE File = '$file'");
- echo mysql_num_rows($result);
- if(mysql_num_rows($result) == 0) {
- $offset = 0;
- if(strpos($stats,$player) < 81){
- $offset = strpos($stats,$player) + 1;
- }
- $Score = preg_replace('/\s+/', '', substr($stats, strpos($stats,"file.") + 5, strpos($stats,$player,strpos($stats,"file.")+$offset) - strpos($stats,"file.") - strlen($player) - 1));
- foreach($races as $e){
- if(strpos($stats,$e[0]) != false){
- if(strpos($stats,$e[0]) < 500){
- $Race = $e[1];
- break;
- }
- }
- }
- foreach($classes as $e){
- if(strpos($stats,$e[0]) != false){
- if(strpos($stats,$e[0]) < 500){
- $Background = $e[1];
- break;
- }
- }
- }
- foreach($gods as $e){
- if(strpos($stats,$e) != false){
- if(strpos($stats,$e) < 500){
- $God = $e;
- break;
- }
- }
- }
- if(!isset($God) || $God == ""){
- $God = "No God";
- }
- $offset = 0;
- if(strpos($stats,$player) < 81){
- $offset = strpos($stats,$player) + 1;
- }
- $Title = substr(preg_replace('/\s+/', '', substr($stats, strpos($stats,$player,$offset) + strlen($player), strpos($stats,"(",strpos($stats,$player,$offset)) - strpos($stats,$player,$offset) - 1- strlen($player))),3);
- $offset = 0;
- if(strpos($player, '... on level') !== false || strpos($player, 'Escaped with the Orb') !== false){
- $offset = strpos($stats,$player) + 1;
- }
- if(strpos($stats,"... on level",$offset) != false){
- $curr = preg_replace('/\s+/', '', substr($stats, strpos($stats,"... on level",$offset) + strlen("... on level"), strpos($stats,".",strpos($stats,"... on level",$offset)+3) - strpos($stats,"... on level",$offset) - strlen("... on level")));
- $int = filter_var($curr, FILTER_SANITIZE_NUMBER_INT);
- if( substr($curr,strlen($int)+5) == "LairofBeasts"){
- $curr = "Lair";
- }elseif(substr($curr,strlen($int)+5) == "Dungeon"){
- $curr = "D";
- }else{
- $curr = substr($curr,strlen($int)+5);
- }
- $Place = $curr . ":" . $int;
- }elseif(strpos($stats,"Escaped with the Orb",$offset) != false){
- $Place = "Won";
- }else{
- $Place = "N/A";
- }
- if($Place == "Won"){
- $Win = true;
- }else{
- $Win = false;
- }
- if($God == "No God"){
- $death = $lines[4];
- }else{
- $death = $lines[5];
- }
- $death = trim($death);
- if(strpos($death,"(") != false){
- $End = substr($death,0,strlen($death) - (strlen($death)- strpos($death,"(")) - 1);
- }else{
- $End = $death;
- }
- $offset = 0;
- if(strpos($player, 'XL:') !== false || strpos($player, 'Next:') !== false){
- $offset = strpos($stats,$player) + 1;
- }
- $XL = trim(substr($stats, strpos($stats,"XL:",$offset) + 4, strpos($stats,"Next:",$offset) - strpos($stats,"XL:",$offset) - 4));
- $offset = 0;
- if(strpos($player, 'Turns:') !== false || strpos($player, 'Time:') !== false){
- $offset = strpos($stats,$player) + 1;
- }
- $Turns = trim(substr($stats, strpos($stats,"Turns:",$offset) + 6, strpos($stats,"Time:",$offset) - strpos($stats,"Turns:",$offset) - 8));
- $offset = 0;
- if(strpos($player, 'Time:') !== false || strpos($player, 'Health:') !== false){
- $offset = strpos($stats,$player) + 1;
- }
- $Duration = trim(substr($stats, strpos($stats,"Time:",$offset) + 5, strpos($stats,"Health:",$offset) - strpos($stats,"Time:",$offset) - 5));
- $offset = 0;
- if(strpos($player, 'Health:') !== false || strpos($player, '/') !== false){
- $offset = strpos($stats,$player) + 1;
- }
- $HP_at_End = trim(substr($stats, strpos($stats,"Health:",$offset) + 7, strpos($stats,"/",$offset +strpos($stats,"/",$offset) + 1 ) - strpos($stats,"Health:",$offset) - 7));
- $Version = trim(substr($stats, strpos($stats,"version") + 8, 7));
- $offset = 0;
- if(strpos($player, 'Grand Total:') !== false || strpos($player, 'creatures vanquished') !== false || strpos($player, 'creature vanquished') !== false){
- $offset = strpos($stats,$player) + 1;
- }
- if(strpos($stats, 'Grand Total:',$offset) !== false){
- $Creatures_Vanquished = trim(substr($stats, strpos($stats,"Grand Total:",$offset) + 12, strpos($stats," ",$offset + strpos($stats,"Grand Total:",$offset) + 13) - strpos($stats,"Grand Total:",$offset) - 12));
- }elseif(strpos($stats, 'creatures vanquished',$offset) !== false){
- $a = 0;
- foreach($lines as $e){
- if(strpos($e,"creatures vanquished") !== false && $a > 5){
- $Creatures_Vanquished = filter_var($e, FILTER_SANITIZE_NUMBER_INT);
- break;
- }
- $a++;
- }
- }elseif(strpos($stats, 'creature vanquished',$offset) !== false){
- $Creatures_Vanquished = 1;
- }else{
- $Creatures_Vanquished = 0;
- }
- $offset = 0;
- if(strpos($player, 'Gold:') !== false || strpos($player, 'SH:') !== false){
- $offset = strpos($stats,$player) + 1;
- }
- $Gold_Death = trim(substr($stats, strpos($stats,"Gold:",$offset) + 5, strpos($stats,"SH:",$offset) - strpos($stats,"Gold:",$offset) - 5));
- $offset = 0;
- if(strpos($player, 'You collected') !== false || strpos($player, 'gold pieces') !== false){
- $offset = strpos($stats,$player) + 1;
- }
- $Gold_Total = trim(substr($stats, strpos($stats,"You collected",$offset) + 13, strpos($stats,"gold pieces",$offset) - strpos($stats,"You collected",$offset) - 13));
- $offset = 0;
- if(strpos($player, 'You spent') !== false || strpos($player, 'gold pieces') !== false){
- $offset = strpos($stats,$player) + 1;
- }
- $Gold_Spent = trim(substr($stats, strpos($stats,"You spent",$offset) + 9, strpos($stats,"gold pieces",$offset + strpos($stats,"gold pieces",$offset) + 1) - strpos($stats,"You spent",$offset) - 9));
- $out = str_replace("morgue-$dead-","",$file);
- $year = substr($out,0,4);
- $monthNum = substr($out,4,2);
- $monthName = date("F", mktime(0, 0, 0, $monthNum, 10));
- $day = substr($out,6,2);
- $hour = substr($out,9,2);
- $minute = substr($out,11,2);
- $seconds = substr($out,13,2);
- $Date = "$monthName-$day-$year-$hour:$minute:$seconds";
- $offset = 0;
- if(strpos($player, '}:') !== false || strpos($player, 'runes:') !== false){
- $offset = strpos($stats,$player) + 1;
- }
- $Runes = substr(trim(substr($stats, strpos($stats,"}:",$offset) + 2, strpos($stats,"runes:",$offset) - strpos($stats,"}:",$offset) - 2)),0,-3);
- $runes = array();
- $a = 0;
- foreach($lines as $e){
- if(strpos($e,"rune of Zot") !== false && $a > 5){
- $runes[] = trim(substr($e,0,strpos($e,"|")));
- }
- $a++;
- }
- $First_Rune_Turn = $runes[0];
- $sum = 0;
- foreach($runes as $e){
- $sum = $sum + $e - $runes[0];
- }
- $Average_Rune_Turn = $sum /count($runes);
- } else {
- //morgue file already processed
- }
- }
- }
- // For Testing Below
- /*
- $myfile = fopen("/home/crawl/DGL/dgldir/morgue/Crawl/morgue-Crawl-20160421-015318.txt", "r");
- $stats = fread($myfile,filesize("/home/crawl/DGL/dgldir/morgue/Crawl/morgue-Crawl-20160421-015318.txt")); //open a file containing user info for security purposes it is not hard coded
- $lines = file("http://www.jorgrun.rocks/morgue/Crawl/morgue-Crawl-20160421-015318.txt");//file in to an array
- fclose($myfile);
- $player = "Crawl";
- */
- /*
- $myfile = fopen("/home/crawl/DGL/dgldir/morgue/Gramm/morgue-Gramm-20160417-010955.txt", "r");
- $stats = fread($myfile,filesize("/home/crawl/DGL/dgldir/morgue/Gramm/morgue-Gramm-20160417-010955.txt")); //open a file containing user info for security purposes it is not hard coded
- $lines = file("http://www.jorgrun.rocks/morgue/Gramm/morgue-Gramm-20160417-010955.txt");//file in to an array
- fclose($myfile);
- $player = "Gramm";
- */
- /*
- $offset = 0;
- if(strpos($stats,$player) < 81){
- $offset = strpos($stats,$player) + 1;
- }
- $Score = preg_replace('/\s+/', '', substr($stats, strpos($stats,"file.") + 5, strpos($stats,$player,strpos($stats,"file.")+$offset) - strpos($stats,"file.") - strlen($player) - 1));
- */
- /*
- foreach($races as $e){
- if(strpos($stats,$e[0]) != false){
- if(strpos($stats,$e[0]) < 500){
- $Race = $e[1];
- break;
- }
- }
- }
- */
- /*
- foreach($classes as $e){
- if(strpos($stats,$e[0]) != false){
- if(strpos($stats,$e[0]) < 500){
- $Background = $e[1];
- break;
- }
- }
- }
- */
- /*
- foreach($gods as $e){
- if(strpos($stats,$e) != false){
- if(strpos($stats,$e) < 500){
- $God = $e;
- break;
- }
- }
- }
- if(!isset($God) || $God == ""){
- $God = "No God";
- }
- */
- /*
- $offset = 0;
- if(strpos($stats,$player) < 81){
- $offset = strpos($stats,$player) + 1;
- }
- $Title = substr(preg_replace('/\s+/', '', substr($stats, strpos($stats,$player,$offset) + strlen($player), strpos($stats,"(",strpos($stats,$player,$offset)) - strpos($stats,$player,$offset) - 1- strlen($player))),3);
- */
- /*
- $offset = 0;
- if(strpos($player, '... on level') !== false || strpos($player, 'Escaped with the Orb') !== false){
- $offset = strpos($stats,$player) + 1;
- }
- if(strpos($stats,"... on level",$offset) != false){
- $curr = preg_replace('/\s+/', '', substr($stats, strpos($stats,"... on level",$offset) + strlen("... on level"), strpos($stats,".",strpos($stats,"... on level",$offset)+3) - strpos($stats,"... on level",$offset) - strlen("... on level")));
- $int = filter_var($curr, FILTER_SANITIZE_NUMBER_INT);
- if( substr($curr,strlen($int)+5) == "LairofBeasts"){
- $curr = "Lair";
- }elseif(substr($curr,strlen($int)+5) == "Dungeon"){
- $curr = "D";
- }else{
- $curr = substr($curr,strlen($int)+5);
- }
- $Place = $curr . ":" . $int;
- }elseif(strpos($stats,"Escaped with the Orb",$offset) != false){
- $Place = "Won";
- }else{
- $Place = "N/A";
- }
- if($Place == "Won"){
- $Win = true;
- }else{
- $Win = false;
- }
- */
- /*
- if($God == "No God"){
- $death = $lines[4];
- }else{
- $death = $lines[5];
- }
- $death = trim($death);
- if(strpos($death,"(") != false){
- $End = substr($death,0,strlen($death) - (strlen($death)- strpos($death,"(")) - 1);
- }else{
- $End = $death;
- }
- */
- /*
- $offset = 0;
- if(strpos($player, 'XL:') !== false || strpos($player, 'Next:') !== false){
- $offset = strpos($stats,$player) + 1;
- }
- $XL = trim(substr($stats, strpos($stats,"XL:",$offset) + 4, strpos($stats,"Next:",$offset) - strpos($stats,"XL:",$offset) - 4));
- */
- /*
- $offset = 0;
- if(strpos($player, 'Turns:') !== false || strpos($player, 'Time:') !== false){
- $offset = strpos($stats,$player) + 1;
- }
- $Turns = trim(substr($stats, strpos($stats,"Turns:",$offset) + 6, strpos($stats,"Time:",$offset) - strpos($stats,"Turns:",$offset) - 8));
- */
- /*
- $offset = 0;
- if(strpos($player, 'Time:') !== false || strpos($player, 'Health:') !== false){
- $offset = strpos($stats,$player) + 1;
- }
- $Duration = trim(substr($stats, strpos($stats,"Time:",$offset) + 5, strpos($stats,"Health:",$offset) - strpos($stats,"Time:",$offset) - 5));
- */
- /*
- $offset = 0;
- if(strpos($player, 'Health:') !== false || strpos($player, '/') !== false){
- $offset = strpos($stats,$player) + 1;
- }
- $HP_at_End = trim(substr($stats, strpos($stats,"Health:",$offset) + 7, strpos($stats,"/",$offset +strpos($stats,"/",$offset) + 1 ) - strpos($stats,"Health:",$offset) - 7));
- echo $HP_at_End;
- */
- /*
- $Version = trim(substr($stats, strpos($stats,"version") + 8, 7));
- echo $Version;
- */
- /*
- $offset = 0;
- if(strpos($player, 'Grand Total:') !== false || strpos($player, 'creatures vanquished') !== false || strpos($player, 'creature vanquished') !== false){
- $offset = strpos($stats,$player) + 1;
- }
- if(strpos($stats, 'Grand Total:',$offset) !== false){
- $Creatures_Vanquished = trim(substr($stats, strpos($stats,"Grand Total:",$offset) + 12, strpos($stats," ",$offset + strpos($stats,"Grand Total:",$offset) + 13) - strpos($stats,"Grand Total:",$offset) - 12));
- }elseif(strpos($stats, 'creatures vanquished',$offset) !== false){
- $a = 0;
- foreach($lines as $e){
- if(strpos($e,"creatures vanquished") !== false && $a > 5){
- $Creatures_Vanquished = filter_var($e, FILTER_SANITIZE_NUMBER_INT);
- break;
- }
- $a++;
- }
- }elseif(strpos($stats, 'creature vanquished',$offset) !== false){
- $Creatures_Vanquished = 1;
- }else{
- $Creatures_Vanquished = 0;
- }
- echo $Creatures_Vanquished
- */
- /*
- $offset = 0;
- if(strpos($player, 'Gold:') !== false || strpos($player, 'SH:') !== false){
- $offset = strpos($stats,$player) + 1;
- }
- $Gold_Death = trim(substr($stats, strpos($stats,"Gold:",$offset) + 5, strpos($stats,"SH:",$offset) - strpos($stats,"Gold:",$offset) - 5));
- echo $Gold_Death;
- */
- /*
- $offset = 0;
- if(strpos($player, 'You collected') !== false || strpos($player, 'gold pieces') !== false){
- $offset = strpos($stats,$player) + 1;
- }
- $Gold_Total = trim(substr($stats, strpos($stats,"You collected",$offset) + 13, strpos($stats,"gold pieces",$offset) - strpos($stats,"You collected",$offset) - 13));
- echo $Gold_Total;
- */
- /*
- $offset = 0;
- if(strpos($player, 'You spent') !== false || strpos($player, 'gold pieces') !== false){
- $offset = strpos($stats,$player) + 1;
- }
- $Gold_Spent = trim(substr($stats, strpos($stats,"You spent",$offset) + 9, strpos($stats,"gold pieces",$offset + strpos($stats,"gold pieces",$offset) + 1) - strpos($stats,"You spent",$offset) - 9));
- echo $Gold_Spent;
- */
- /*
- $offset = 0;
- if(strpos($player, '}:') !== false || strpos($player, 'runes:') !== false){
- $offset = strpos($stats,$player) + 1;
- }
- $Runes = substr(trim(substr($stats, strpos($stats,"}:",$offset) + 2, strpos($stats,"runes:",$offset) - strpos($stats,"}:",$offset) - 2)),0,-3);
- echo $Runes;
- */
- /*
- $runes = array();
- $a = 0;
- foreach($lines as $e){
- if(strpos($e,"rune of Zot") !== false && $a > 5){
- $runes[] = trim(substr($e,0,strpos($e,"|")));
- }
- $a++;
- }
- $First_Rune_Turn = $runes[0];
- $sum = 0;
- foreach($runes as $e){
- $sum = $sum + $e - $runes[0];
- }
- $Average_Rune_Turn = $sum /count($runes);
- */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement