Advertisement
Guest User

Untitled

a guest
Apr 24th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.09 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors', 1);
  3. ini_set('display_startup_errors', 1);
  4. error_reporting(E_ALL);
  5.  
  6.  
  7. $servername = "localhost";
  8. $username = "ss13";
  9. $password = "ss13";
  10. $dbname = "crawl";
  11. $races = array(
  12. array("Centaur", "Ce"),
  13. array("Deep Dwarf", "DD"),
  14. array("Deep Elf", "DE"),
  15. array("Demigod", "Dg"),
  16. array("Demonspawn", "Ds"),
  17. array("Draconian", "Dr"),
  18. array("Felid", "Fe"),
  19. array("Formicid", "Fo"),
  20. array("Gargoyle", "Gr"),
  21. array("Ghoul", "Gh"),
  22. array("Halfling", "Ha"),
  23. array("High Elf", "HE"),
  24. array("Hill Orc", "HO"),
  25. array("Human", "Hu"),
  26. array("Kobold", "Ko"),
  27. array("Merfolk", "Mf"),
  28. array("Minotaur", "Mi"),
  29. array("Mummy", "Mu"),
  30. array("Naga", "Na"),
  31. array("Octopode", "Op"),
  32. array("Ogre", "Og"),
  33. array("Spriggan", "Sp"),
  34. array("Tengu", "Te"),
  35. array("Troll", "Tr"),
  36. array("Vampire, Vp"),
  37. array("Vine Stalker", "VS")
  38. );
  39. $classes = array(array("Fighter" ,"Fi"),
  40. array("Gladiator" ,"Gl"),
  41. array("Monk" ,"Mo") ,
  42. array("Hunter" ,"Hu"),
  43. array("Assassin" ,"As"),
  44. array("Berserker" ,"Be"),
  45. array("Abyssal Knight" ,"AK"),
  46. array("Chaos Knight" ,"CK"),
  47. array("Skald" ,"Sk"),
  48. array("Enchanter" ,"En"),
  49. array("Transmuter" ,"Tm"),
  50. array("Arcane Marksman" ,"AM"),
  51. array("Warper" ,"Wr"),
  52. array("Wizard" ,"Wz"),
  53. array("Conjurer" ,"Cj"),
  54. array("Summoner" ,"Su"),
  55. array("Necromancer" ,"Ne"),
  56. array("Fire Elementalist" ,"FE"),
  57. array("Ice Elementalist" ,"IE"),
  58. array("Air Elementalist" ,"AE"),
  59. array("Earth Elementalist" ,"EE"),
  60. array("Venom Mage" ,"VM"),
  61. array("Artificer" ,"Ar"),
  62. array("Wanderer" ,"Wn"));
  63.  
  64. $gods = array(
  65. "Ashenzari",
  66. "Beogh",
  67. "Cheibriados",
  68. "Dithmenos",
  69. "Elyvilon",
  70. "Fedhas Madash",
  71. "Gozag Ym Sagoz",
  72. "Jiyva",
  73. "Kikubaaqudgha",
  74. "Lugonu",
  75. "Makhleb",
  76. "Nemelex Xobeh",
  77. "Okawaru",
  78. "Qazlal",
  79. "Ru",
  80. "Sif Muna",
  81. "The Shining One",
  82. "Trog",
  83. "Vehumet",
  84. "Xom",
  85. "Yredelemnul",
  86. "Zin"
  87. );
  88. // Create connection
  89. $conn = mysqli_connect($servername, $username, $password, $dbname);
  90. //Get all players in the morgue
  91. $path = "/home/crawl/DGL/dgldir/morgue/";
  92. $dirs = array();
  93. $results = scandir($path);
  94. foreach ($results as $result){
  95. if($result === '.' or $result === '..') continue;
  96. if(is_dir($path . '/' . $result)){
  97. $dirs[] = $result;
  98. }
  99. }
  100. foreach($dirs as $player){
  101. $path = "/home/crawl/DGL/dgldir/morgue/" . $player;
  102. $files = array();
  103. $results = scandir($path);
  104. foreach ($results as $result){
  105. if($result === '.' or $result === '..') continue;
  106. if(is_file($path . '/' . $result)){
  107. $files[] = $result;
  108. }
  109. }
  110. $morgue = array();
  111. foreach($files as $file){
  112. $end = substr($file,-3,3);
  113. if($end == "txt" && $file != "$player.txt" && substr($file,0,5) != "crash"){
  114. $morgue[] = $file;
  115. }
  116. }
  117. $player_morgue = $player . "_morgue";
  118. //check to make tables
  119. $val = mysqli_query($conn, "select 1 from `$player_morgue` LIMIT 1");
  120.  
  121. if($val !== FALSE)
  122. {
  123. continue;
  124. }
  125. else
  126. {
  127. $sql = "CREATE TABLE $player_morgue LIKE crawl_morgue";
  128. mysqli_query($conn, $sql);
  129. }
  130.  
  131. $val = mysqli_query($conn, "select 1 from `$player` LIMIT 1");
  132.  
  133. if($val !== FALSE)
  134. {
  135. continue;
  136. }
  137. else
  138. {
  139. $sql = "CREATE TABLE $player LIKE crawl_player";
  140. mysqli_query($conn, $sql);
  141. }
  142.  
  143. foreach($morgue as $file){
  144. $myfile = fopen($path . "/$file", "r");
  145. $stats = fread($myfile,filesize($path . "/$file")); //open a file containing user info for security purposes it is not hard coded
  146. $lines = file("http://www.jorgrun.rocks/morgue/$player/$file");//file in to an array
  147. fclose($myfile);
  148.  
  149. $result = mysqli_query($conn, "SELECT * FROM $player_morgue WHERE File = '$file'");
  150. echo mysql_num_rows($result);
  151. if(mysql_num_rows($result) == 0) {
  152.  
  153. $offset = 0;
  154. if(strpos($stats,$player) < 81){
  155. $offset = strpos($stats,$player) + 1;
  156. }
  157. $Score = preg_replace('/\s+/', '', substr($stats, strpos($stats,"file.") + 5, strpos($stats,$player,strpos($stats,"file.")+$offset) - strpos($stats,"file.") - strlen($player) - 1));
  158.  
  159.  
  160. foreach($races as $e){
  161. if(strpos($stats,$e[0]) != false){
  162. if(strpos($stats,$e[0]) < 500){
  163. $Race = $e[1];
  164. break;
  165. }
  166. }
  167. }
  168. foreach($classes as $e){
  169. if(strpos($stats,$e[0]) != false){
  170. if(strpos($stats,$e[0]) < 500){
  171. $Background = $e[1];
  172. break;
  173. }
  174. }
  175. }
  176. foreach($gods as $e){
  177. if(strpos($stats,$e) != false){
  178. if(strpos($stats,$e) < 500){
  179. $God = $e;
  180. break;
  181. }
  182. }
  183. }
  184. if(!isset($God) || $God == ""){
  185. $God = "No God";
  186. }
  187.  
  188. $offset = 0;
  189. if(strpos($stats,$player) < 81){
  190. $offset = strpos($stats,$player) + 1;
  191. }
  192. $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);
  193.  
  194. $offset = 0;
  195. if(strpos($player, '... on level') !== false || strpos($player, 'Escaped with the Orb') !== false){
  196. $offset = strpos($stats,$player) + 1;
  197. }
  198. if(strpos($stats,"... on level",$offset) != false){
  199. $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")));
  200. $int = filter_var($curr, FILTER_SANITIZE_NUMBER_INT);
  201. if( substr($curr,strlen($int)+5) == "LairofBeasts"){
  202. $curr = "Lair";
  203. }elseif(substr($curr,strlen($int)+5) == "Dungeon"){
  204. $curr = "D";
  205. }else{
  206. $curr = substr($curr,strlen($int)+5);
  207. }
  208. $Place = $curr . ":" . $int;
  209. }elseif(strpos($stats,"Escaped with the Orb",$offset) != false){
  210. $Place = "Won";
  211. }else{
  212. $Place = "N/A";
  213. }
  214.  
  215. if($Place == "Won"){
  216. $Win = true;
  217. }else{
  218. $Win = false;
  219. }
  220.  
  221. if($God == "No God"){
  222. $death = $lines[4];
  223. }else{
  224. $death = $lines[5];
  225. }
  226. $death = trim($death);
  227. if(strpos($death,"(") != false){
  228. $End = substr($death,0,strlen($death) - (strlen($death)- strpos($death,"(")) - 1);
  229. }else{
  230. $End = $death;
  231. }
  232.  
  233. $offset = 0;
  234. if(strpos($player, 'XL:') !== false || strpos($player, 'Next:') !== false){
  235. $offset = strpos($stats,$player) + 1;
  236. }
  237. $XL = trim(substr($stats, strpos($stats,"XL:",$offset) + 4, strpos($stats,"Next:",$offset) - strpos($stats,"XL:",$offset) - 4));
  238.  
  239.  
  240. $offset = 0;
  241. if(strpos($player, 'Turns:') !== false || strpos($player, 'Time:') !== false){
  242. $offset = strpos($stats,$player) + 1;
  243. }
  244. $Turns = trim(substr($stats, strpos($stats,"Turns:",$offset) + 6, strpos($stats,"Time:",$offset) - strpos($stats,"Turns:",$offset) - 8));
  245.  
  246. $offset = 0;
  247. if(strpos($player, 'Time:') !== false || strpos($player, 'Health:') !== false){
  248. $offset = strpos($stats,$player) + 1;
  249. }
  250. $Duration = trim(substr($stats, strpos($stats,"Time:",$offset) + 5, strpos($stats,"Health:",$offset) - strpos($stats,"Time:",$offset) - 5));
  251.  
  252. $offset = 0;
  253. if(strpos($player, 'Health:') !== false || strpos($player, '/') !== false){
  254. $offset = strpos($stats,$player) + 1;
  255. }
  256. $HP_at_End = trim(substr($stats, strpos($stats,"Health:",$offset) + 7, strpos($stats,"/",$offset +strpos($stats,"/",$offset) + 1 ) - strpos($stats,"Health:",$offset) - 7));
  257.  
  258. $Version = trim(substr($stats, strpos($stats,"version") + 8, 7));
  259.  
  260. $offset = 0;
  261. if(strpos($player, 'Grand Total:') !== false || strpos($player, 'creatures vanquished') !== false || strpos($player, 'creature vanquished') !== false){
  262. $offset = strpos($stats,$player) + 1;
  263. }
  264. if(strpos($stats, 'Grand Total:',$offset) !== false){
  265. $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));
  266. }elseif(strpos($stats, 'creatures vanquished',$offset) !== false){
  267. $a = 0;
  268. foreach($lines as $e){
  269. if(strpos($e,"creatures vanquished") !== false && $a > 5){
  270. $Creatures_Vanquished = filter_var($e, FILTER_SANITIZE_NUMBER_INT);
  271. break;
  272. }
  273. $a++;
  274. }
  275. }elseif(strpos($stats, 'creature vanquished',$offset) !== false){
  276. $Creatures_Vanquished = 1;
  277. }else{
  278. $Creatures_Vanquished = 0;
  279. }
  280.  
  281. $offset = 0;
  282. if(strpos($player, 'Gold:') !== false || strpos($player, 'SH:') !== false){
  283. $offset = strpos($stats,$player) + 1;
  284. }
  285. $Gold_Death = trim(substr($stats, strpos($stats,"Gold:",$offset) + 5, strpos($stats,"SH:",$offset) - strpos($stats,"Gold:",$offset) - 5));
  286.  
  287. $offset = 0;
  288. if(strpos($player, 'You collected') !== false || strpos($player, 'gold pieces') !== false){
  289. $offset = strpos($stats,$player) + 1;
  290. }
  291. $Gold_Total = trim(substr($stats, strpos($stats,"You collected",$offset) + 13, strpos($stats,"gold pieces",$offset) - strpos($stats,"You collected",$offset) - 13));
  292.  
  293.  
  294. $offset = 0;
  295. if(strpos($player, 'You spent') !== false || strpos($player, 'gold pieces') !== false){
  296. $offset = strpos($stats,$player) + 1;
  297. }
  298. $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));
  299.  
  300. $out = str_replace("morgue-$dead-","",$file);
  301. $year = substr($out,0,4);
  302. $monthNum = substr($out,4,2);
  303. $monthName = date("F", mktime(0, 0, 0, $monthNum, 10));
  304. $day = substr($out,6,2);
  305. $hour = substr($out,9,2);
  306. $minute = substr($out,11,2);
  307. $seconds = substr($out,13,2);
  308. $Date = "$monthName-$day-$year-$hour:$minute:$seconds";
  309.  
  310. $offset = 0;
  311. if(strpos($player, '}:') !== false || strpos($player, 'runes:') !== false){
  312. $offset = strpos($stats,$player) + 1;
  313. }
  314. $Runes = substr(trim(substr($stats, strpos($stats,"}:",$offset) + 2, strpos($stats,"runes:",$offset) - strpos($stats,"}:",$offset) - 2)),0,-3);
  315.  
  316. $runes = array();
  317. $a = 0;
  318. foreach($lines as $e){
  319. if(strpos($e,"rune of Zot") !== false && $a > 5){
  320. $runes[] = trim(substr($e,0,strpos($e,"|")));
  321. }
  322. $a++;
  323. }
  324. $First_Rune_Turn = $runes[0];
  325. $sum = 0;
  326. foreach($runes as $e){
  327. $sum = $sum + $e - $runes[0];
  328. }
  329. $Average_Rune_Turn = $sum /count($runes);
  330.  
  331.  
  332. } else {
  333. //morgue file already processed
  334. }
  335. }
  336.  
  337.  
  338. }
  339.  
  340.  
  341.  
  342.  
  343. // For Testing Below
  344. /*
  345. $myfile = fopen("/home/crawl/DGL/dgldir/morgue/Crawl/morgue-Crawl-20160421-015318.txt", "r");
  346. $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
  347. $lines = file("http://www.jorgrun.rocks/morgue/Crawl/morgue-Crawl-20160421-015318.txt");//file in to an array
  348. fclose($myfile);
  349. $player = "Crawl";
  350. */
  351. /*
  352. $myfile = fopen("/home/crawl/DGL/dgldir/morgue/Gramm/morgue-Gramm-20160417-010955.txt", "r");
  353. $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
  354. $lines = file("http://www.jorgrun.rocks/morgue/Gramm/morgue-Gramm-20160417-010955.txt");//file in to an array
  355. fclose($myfile);
  356. $player = "Gramm";
  357. */
  358. /*
  359. $offset = 0;
  360. if(strpos($stats,$player) < 81){
  361. $offset = strpos($stats,$player) + 1;
  362. }
  363. $Score = preg_replace('/\s+/', '', substr($stats, strpos($stats,"file.") + 5, strpos($stats,$player,strpos($stats,"file.")+$offset) - strpos($stats,"file.") - strlen($player) - 1));
  364. */
  365. /*
  366. foreach($races as $e){
  367. if(strpos($stats,$e[0]) != false){
  368. if(strpos($stats,$e[0]) < 500){
  369. $Race = $e[1];
  370. break;
  371. }
  372. }
  373. }
  374. */
  375. /*
  376. foreach($classes as $e){
  377. if(strpos($stats,$e[0]) != false){
  378. if(strpos($stats,$e[0]) < 500){
  379. $Background = $e[1];
  380. break;
  381. }
  382. }
  383. }
  384. */
  385. /*
  386. foreach($gods as $e){
  387. if(strpos($stats,$e) != false){
  388. if(strpos($stats,$e) < 500){
  389. $God = $e;
  390. break;
  391. }
  392. }
  393. }
  394. if(!isset($God) || $God == ""){
  395. $God = "No God";
  396. }
  397. */
  398. /*
  399. $offset = 0;
  400. if(strpos($stats,$player) < 81){
  401. $offset = strpos($stats,$player) + 1;
  402. }
  403. $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);
  404. */
  405. /*
  406. $offset = 0;
  407. if(strpos($player, '... on level') !== false || strpos($player, 'Escaped with the Orb') !== false){
  408. $offset = strpos($stats,$player) + 1;
  409. }
  410. if(strpos($stats,"... on level",$offset) != false){
  411. $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")));
  412. $int = filter_var($curr, FILTER_SANITIZE_NUMBER_INT);
  413. if( substr($curr,strlen($int)+5) == "LairofBeasts"){
  414. $curr = "Lair";
  415. }elseif(substr($curr,strlen($int)+5) == "Dungeon"){
  416. $curr = "D";
  417. }else{
  418. $curr = substr($curr,strlen($int)+5);
  419. }
  420. $Place = $curr . ":" . $int;
  421. }elseif(strpos($stats,"Escaped with the Orb",$offset) != false){
  422. $Place = "Won";
  423. }else{
  424. $Place = "N/A";
  425. }
  426.  
  427. if($Place == "Won"){
  428. $Win = true;
  429. }else{
  430. $Win = false;
  431. }
  432. */
  433. /*
  434. if($God == "No God"){
  435. $death = $lines[4];
  436. }else{
  437. $death = $lines[5];
  438. }
  439. $death = trim($death);
  440. if(strpos($death,"(") != false){
  441. $End = substr($death,0,strlen($death) - (strlen($death)- strpos($death,"(")) - 1);
  442. }else{
  443. $End = $death;
  444. }
  445. */
  446. /*
  447. $offset = 0;
  448. if(strpos($player, 'XL:') !== false || strpos($player, 'Next:') !== false){
  449. $offset = strpos($stats,$player) + 1;
  450. }
  451. $XL = trim(substr($stats, strpos($stats,"XL:",$offset) + 4, strpos($stats,"Next:",$offset) - strpos($stats,"XL:",$offset) - 4));
  452. */
  453. /*
  454. $offset = 0;
  455. if(strpos($player, 'Turns:') !== false || strpos($player, 'Time:') !== false){
  456. $offset = strpos($stats,$player) + 1;
  457. }
  458. $Turns = trim(substr($stats, strpos($stats,"Turns:",$offset) + 6, strpos($stats,"Time:",$offset) - strpos($stats,"Turns:",$offset) - 8));
  459. */
  460. /*
  461. $offset = 0;
  462. if(strpos($player, 'Time:') !== false || strpos($player, 'Health:') !== false){
  463. $offset = strpos($stats,$player) + 1;
  464. }
  465. $Duration = trim(substr($stats, strpos($stats,"Time:",$offset) + 5, strpos($stats,"Health:",$offset) - strpos($stats,"Time:",$offset) - 5));
  466. */
  467. /*
  468. $offset = 0;
  469. if(strpos($player, 'Health:') !== false || strpos($player, '/') !== false){
  470. $offset = strpos($stats,$player) + 1;
  471. }
  472. $HP_at_End = trim(substr($stats, strpos($stats,"Health:",$offset) + 7, strpos($stats,"/",$offset +strpos($stats,"/",$offset) + 1 ) - strpos($stats,"Health:",$offset) - 7));
  473. echo $HP_at_End;
  474. */
  475. /*
  476. $Version = trim(substr($stats, strpos($stats,"version") + 8, 7));
  477. echo $Version;
  478. */
  479. /*
  480. $offset = 0;
  481. if(strpos($player, 'Grand Total:') !== false || strpos($player, 'creatures vanquished') !== false || strpos($player, 'creature vanquished') !== false){
  482. $offset = strpos($stats,$player) + 1;
  483. }
  484. if(strpos($stats, 'Grand Total:',$offset) !== false){
  485. $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));
  486. }elseif(strpos($stats, 'creatures vanquished',$offset) !== false){
  487. $a = 0;
  488. foreach($lines as $e){
  489. if(strpos($e,"creatures vanquished") !== false && $a > 5){
  490. $Creatures_Vanquished = filter_var($e, FILTER_SANITIZE_NUMBER_INT);
  491. break;
  492. }
  493. $a++;
  494. }
  495. }elseif(strpos($stats, 'creature vanquished',$offset) !== false){
  496. $Creatures_Vanquished = 1;
  497. }else{
  498. $Creatures_Vanquished = 0;
  499. }
  500. echo $Creatures_Vanquished
  501. */
  502. /*
  503. $offset = 0;
  504. if(strpos($player, 'Gold:') !== false || strpos($player, 'SH:') !== false){
  505. $offset = strpos($stats,$player) + 1;
  506. }
  507. $Gold_Death = trim(substr($stats, strpos($stats,"Gold:",$offset) + 5, strpos($stats,"SH:",$offset) - strpos($stats,"Gold:",$offset) - 5));
  508. echo $Gold_Death;
  509. */
  510. /*
  511. $offset = 0;
  512. if(strpos($player, 'You collected') !== false || strpos($player, 'gold pieces') !== false){
  513. $offset = strpos($stats,$player) + 1;
  514. }
  515. $Gold_Total = trim(substr($stats, strpos($stats,"You collected",$offset) + 13, strpos($stats,"gold pieces",$offset) - strpos($stats,"You collected",$offset) - 13));
  516. echo $Gold_Total;
  517. */
  518. /*
  519. $offset = 0;
  520. if(strpos($player, 'You spent') !== false || strpos($player, 'gold pieces') !== false){
  521. $offset = strpos($stats,$player) + 1;
  522. }
  523. $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));
  524. echo $Gold_Spent;
  525. */
  526.  
  527. /*
  528. $offset = 0;
  529. if(strpos($player, '}:') !== false || strpos($player, 'runes:') !== false){
  530. $offset = strpos($stats,$player) + 1;
  531. }
  532. $Runes = substr(trim(substr($stats, strpos($stats,"}:",$offset) + 2, strpos($stats,"runes:",$offset) - strpos($stats,"}:",$offset) - 2)),0,-3);
  533. echo $Runes;
  534. */
  535. /*
  536. $runes = array();
  537. $a = 0;
  538. foreach($lines as $e){
  539. if(strpos($e,"rune of Zot") !== false && $a > 5){
  540. $runes[] = trim(substr($e,0,strpos($e,"|")));
  541. }
  542. $a++;
  543. }
  544. $First_Rune_Turn = $runes[0];
  545. $sum = 0;
  546. foreach($runes as $e){
  547. $sum = $sum + $e - $runes[0];
  548. }
  549. $Average_Rune_Turn = $sum /count($runes);
  550. */
  551.  
  552.  
  553. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement