Advertisement
Guest User

Untitled

a guest
Sep 5th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.22 KB | None | 0 0
  1. <?php
  2. require_once __DIR__.'/../../wp-content/themes/galaxynetwork/lib/vendor/autoload.php';
  3. require_once __DIR__.'/../../wp-content/themes/galaxynetwork/autoload.php';
  4. require_once __DIR__.'/../../wp-content/themes/galaxynetwork/template-parts/rust/servers.php';
  5. require_once __DIR__.'/../../wp-content/themes/galaxynetwork/template-parts/rust/rust-info.php';
  6. require_once(__DIR__."/ts3admin.class.php");
  7. require_once(__DIR__."/connect.php");
  8. require_once(__DIR__."/mc.php");
  9.  
  10. use Api\Battlemetrics\Battlemetrics;
  11.  
  12. function ts3info($ts3server, $ts3qport, $ts3port, $ts3user = null, $ts3pass = null) {
  13. $ts3 = new ts3admin($ts3server, $ts3qport);
  14. $connection = $ts3->connect();
  15. if ($connection['success']) {
  16. $selected = $ts3->selectServer($ts3port, 'port', true);
  17. if ($selected['success']) {
  18. if ($ts3user != null && $ts3pass != null) {
  19. $login = $ts3->login($ts3user, $ts3pass);
  20. }
  21. $sinfo = $ts3->serverInfo();
  22. if ($sinfo['success']) {
  23. $sinfo = $sinfo["data"];
  24.  
  25. $cslots = intval($sinfo["virtualserver_clientsonline"])-intval($sinfo["virtualserver_queryclientsonline"]);
  26. $maxslots = intval($sinfo["virtualserver_maxclients"]);
  27.  
  28. $query = intval($sinfo["virtualserver_queryclientsonline"])-1;
  29.  
  30. return array(
  31. "cslots" => $cslots,
  32. "maxslots" => $maxslots,
  33. "query" => $query
  34. );
  35. } else {
  36. $errors = $sinfo['errors'];
  37. }
  38. } else {
  39. $errors = $selected['errors'];
  40. }
  41. } else {
  42. $errors = $connection['errors'];
  43. }
  44.  
  45. file_put_contents('error_ts3info.log', $errors);
  46.  
  47. return array(
  48. "cslots" => "--",
  49. "maxslots" => "--",
  50. "query" => "--"
  51. );
  52. }
  53.  
  54. function getTs3Info($ts3server, $ts3qport, $ts3port, $ts3user, $ts3pass) {
  55. // Cache system
  56. $driver = new Stash\Driver\FileSystem(array());
  57. $pool = new Stash\Pool($driver);
  58. $item = $pool->getItem('api/teamspeak/serverinfo/'.$ts3server);
  59.  
  60. // Using an age.
  61. $data = $item->get();
  62. if($item->isMiss())
  63. {
  64. $data = ts3info($ts3server, $ts3qport, $ts3port, $ts3user, $ts3pass);
  65.  
  66. $item->set($data);
  67. $item->expiresAfter(60);
  68. $pool->save($item);
  69. }
  70. return $data;
  71. }
  72.  
  73. function getBattlemetricsInfo($token, $servers) {
  74. $battlemetrics = new Battlemetrics($token);
  75. // Cache system
  76. $driver = new Stash\Driver\FileSystem(array());
  77. $pool = new Stash\Pool($driver);
  78. // Get server infos
  79. $serverInfo = array();
  80. $i = 0;
  81. // Battlemetrics info
  82. $players = 0;
  83. $maxplayers = 0;
  84. foreach ($servers as $server) {
  85. $item = $pool->getItem('api/battlemetrics/serverinfo/'.$server);
  86. // Using an age.
  87. $data = $item->get();
  88. if($item->isMiss())
  89. {
  90. $item->lock();
  91.  
  92. $newdata = $battlemetrics->getServerInfo($server);
  93. // Respecting the rate limit ...
  94. $i++;
  95.  
  96. if ($i%5==0) sleep(2);
  97.  
  98. if (!$newdata->error) {
  99. $data = $newdata;
  100. } else {
  101. sleep(5);
  102. }
  103.  
  104. $item->set($data);
  105.  
  106. // Cache expires after two minutes.
  107. $item->expiresAfter(120);
  108.  
  109. $pool->save($item);
  110. }
  111. $serverInfo[$server] = $data;
  112. $players += $data->getPlayers();
  113. $maxplayers += $data->getMaxPlayers();
  114. }
  115.  
  116. return array(
  117. "players" => $players,
  118. "maxplayers" => $maxplayers
  119. );
  120. }
  121.  
  122. function getRustInfo($token, $servers) {
  123. return getBattlemetricsInfo($token, $servers);
  124. }
  125.  
  126. function getArmaInfo($token, $servers) {
  127. return getBattlemetricsInfo($token, $servers);
  128. }
  129.  
  130. function makeBanner($ts3info, $rustinfo, $armainfo, $mcinfo) {
  131. header('Content-type: image/png');
  132. $datum = date("d.m.Y");
  133. $uhrzeit = date("H:i");
  134. //$text = "$uhrzeit Uhr | $datum | $cslots/$maxslots User(+$query)";
  135. $image = imagecreatefrompng('GN_PHP_Banner.png');
  136.  
  137. $x = 40;
  138.  
  139. $cslots = $ts3info['cslots'];
  140. $maxslots = $ts3info['maxslots'];
  141. $teamspeak_text = "$cslots";
  142. $text_color = imagecolorallocate($image, 255, 255, 255);
  143. imagestring($image, 5, $x, 62, $teamspeak_text, $text_color);
  144.  
  145. $rplayers = $rustinfo['players'];
  146. $rmaxplayers = $rustinfo['maxplayers'];
  147. $rust_text = "$rplayers";
  148. imagestring($image, 5, $x, 118, $rust_text, $text_color);
  149.  
  150. $x2 = 700;
  151.  
  152. $mc_text = "$mcinfo";
  153. imagestring($image, 5, $x2, 62, $mc_text, $text_color);
  154.  
  155. $aplayers = $armainfo['players'];
  156. $amaxplayers = $armainfo['maxplayers'];
  157. $arma_text = "$aplayers";
  158. imagestring($image, 5, $x2, 118, $arma_text, $text_color);
  159.  
  160. imagepng($image);
  161. }
  162.  
  163. $arma_servers = array(1419191, 1372483);
  164.  
  165. $ts3info = getTs3Info($ts3server, $ts3qport, $ts3port, $ts3user, $ts3pass);
  166. $rustinfo = getRustInfo($rust_token, array_keys($servers));
  167. $armainfo = getArmaInfo($rust_token, $arma_servers);
  168. $mcinfo = getMinecraftInfo();
  169. makeBanner($ts3info, $rustinfo, $armainfo, $mcinfo);
  170.  
  171. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement