Advertisement
Guest User

PHP script status

a guest
Jun 28th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. <?php
  2. /* _____ _ _
  3. /\ / ____| | | |
  4. / \__ _____ ___ ___ _ __ ___ ___| (___ | |_ __ _| |_ _ _ ___
  5. / /\ \ \ /\ / / _ \/ __|/ _ \| '_ ` _ \ / _ \\___ \| __/ _` | __| | | / __|
  6. / ____ \ V V / __/\__ \ (_) | | | | | | __/____) | || (_| | |_| |_| \__ \
  7. /_/ \_\_/\_/ \___||___/\___/|_| |_| |_|\___|_____/ \__\__,_|\__|\__,_|___/
  8.  
  9. @name AwesomeStatus
  10. @author Tyzoid
  11. @version 0.5
  12. */
  13.  
  14. // Parameters:
  15. $server = "mc40.crew.sk";
  16. $serverport = "25571";
  17. $supress_nonessential = false;
  18.  
  19. // Check Dependencies
  20. $dependencies = array(
  21. "PHP: FastCGI" => array(
  22. "fastcgi_finish_request" => array("type" => "function", "required" => false),
  23. ),
  24. "PHP: GD2 Library" => array(
  25. "ImageCreateFromPNG" => array("type" => "function", "required" => true),
  26. ),
  27. "Font: newscycle.ttf" => array(
  28. "newsycle.ttf" => array("type" => "file", "required" => true),
  29. ),
  30. "Image: online.png/offline.png" => array(
  31. "online.png" => array("type" => "file", "required" => true),
  32. "offline.png" => array("type" => "file", "required" => true),
  33. ),
  34. );
  35.  
  36. $allgood = true;
  37. foreach($dependencies as $dname => $dependency){
  38. if (empty($dependency) || ! is_array($dependency)) continue;
  39.  
  40. foreach ($dependency as $name => $component){
  41. $missing = false;
  42. $level = ($component['required']? "[Error]":"[Warning]");
  43.  
  44. if($component["required"] === true){
  45. $missing = $missing || (!($component['type'] !== "file" || file_exists($name)));
  46. $missing = $missing || (!($component['type'] !== "function" || function_exists($name)));
  47. } else {
  48. // Only print warning messages if not overridden:
  49. $missing = $missing || (!($component['type'] !== "file" || file_exists($name)) && !$supress_nonessential);
  50. $missing = $missing || (!($component['type'] !== "function" || function_exists($name)) && !$supress_nonessential);
  51. }
  52.  
  53. if($missing){
  54. echo "$level Missing Dependency: '$dname'. Component '$name' of type '{$component['type']}' could not be found<br />\n";
  55. $allgood = false;
  56. }
  57. }
  58. }
  59.  
  60. if ($allgood === false) die("Not all dependencies are met. Please resolve these dependencies and run again.");
  61.  
  62. ignore_user_abort(true);
  63. function query($ip, $port){
  64. @$f = fsockopen($ip, $port, $errorno, $errordesc, 2);
  65. if($f === false) return false; //connection failed
  66. stream_set_timeout($f, 2);
  67. fwrite($f, "\xfe\x01");
  68. $data = fread($f, 256);
  69. if(substr($data, 0, 1) != "\xff") return false; //Not a minecraft server
  70. $data2 = mb_convert_encoding(substr($data, 3), 'UTF8', 'UCS-2');
  71. if(strpos($data2, "\0") !== false) $data = explode("\0", $data2); //1.5.1 servers
  72. else $data = explode("§", mb_convert_encoding(substr($data, 3), 'UTF8', 'UCS-2'));
  73. return array(
  74. "players" => intval($data[count($data)-2]),
  75. "maxplayers" => intval($data[count($data)-1])
  76. );
  77. }
  78.  
  79. $expired = true;
  80. $online = false;
  81. $file = fopen("check.txt", "r");
  82. if(!feof($file)) {
  83. $line = fgets($file);
  84. $online = (substr($line,0,1) === "t");
  85. $players = intval(substr($line,1,3));
  86. $expired = (intval(substr($line,4))+60*1 < time());
  87. $waituntilafter = (intval(substr($line,4))+60*4 > time());
  88. }
  89. fclose($file);
  90.  
  91. if($expired === true && $waituntilafter === false){
  92. $info = query($server,$serverport);
  93. $file = fopen("check.txt", "w");
  94. fwrite($file,(($info !== false)?"t":"f"));
  95. fwrite($file,sprintf("%03d", (($info !== false)?$info['players']:0)));
  96. fwrite($file,(string)time());
  97. fclose($file);
  98.  
  99. $players = (($info !== false)?$info['players']:0);
  100. } else {
  101. $info = $online;
  102. }
  103.  
  104. if($info === false){
  105. $name = './offline.png';
  106. $fp = fopen($name, 'rb');
  107.  
  108. header("Content-Type: image/png");
  109. header("Content-Length: " . filesize($name));
  110.  
  111. fpassthru($fp);
  112. } else {
  113. $name = "./online.png";
  114. $image = ImageCreateFromPNG($name);
  115. imagesavealpha($image, true);
  116. $color = imagecolorallocate($image, 64, 64, 64); // #444
  117. imagettftext($image, 24, 0, 33, 86, $color, 'newscycle.ttf', sprintf("%02d", $players).'/16');
  118. header("Content-Type: image/png");
  119. imagepng($image);
  120. }
  121.  
  122. if (function_exists("fastcgi_finish_request")) fastcgi_finish_request();
  123.  
  124. if($expired === true && $waituntilafter === true){
  125. $info = query($server,$serverport);
  126. $file = fopen("check.txt", "w");
  127. fwrite($file,(($info !== false)?"t":"f"));
  128. fwrite($file,sprintf("%03d", (($info !== false)?$info['players']:0)));
  129. fwrite($file,(string)time());
  130. fclose($file);
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement