Advertisement
Guest User

Untitled

a guest
May 25th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | None | 0 0
  1. <?php
  2.  
  3. require_once __DIR__.'/../../wp-content/themes/galaxynetwork/lib/vendor/autoload.php';
  4.  
  5. require_once __DIR__.'/../../wp-content/themes/galaxynetwork/template-parts/rust/Rust.class.php';
  6.  
  7. require_once __DIR__.'/../../wp-content/themes/galaxynetwork/template-parts/rust/servers.php';
  8.  
  9. require_once(__DIR__."/ts3admin.class.php");
  10.  
  11. require_once(__DIR__."/connect.php");
  12.  
  13.  
  14.  
  15. function ts3info($ts3server, $ts3qport, $ts3port, $ts3user = null, $ts3pass = null) {
  16.  
  17. $ts3 = new ts3admin($ts3server, $ts3qport);
  18.  
  19. $connection = $ts3->connect();
  20.  
  21. if ($connection['success']) {
  22.  
  23. $selected = $ts3->selectServer($ts3port, 'port', true);
  24.  
  25. if ($selected['success']) {
  26.  
  27. if ($ts3user != null && $ts3pass != null) {
  28.  
  29. $login = $ts3->login($ts3user, $ts3pass);
  30.  
  31. }
  32.  
  33. $sinfo = $ts3->serverInfo();
  34.  
  35. if ($sinfo['success']) {
  36.  
  37. $sinfo = $sinfo["data"];
  38.  
  39.  
  40.  
  41. $cslots = intval($sinfo["virtualserver_clientsonline"])-intval($sinfo["virtualserver_queryclientsonline"]);
  42.  
  43. $maxslots = intval($sinfo["virtualserver_maxclients"]);
  44.  
  45.  
  46.  
  47. $query = intval($sinfo["virtualserver_queryclientsonline"])-1;
  48.  
  49.  
  50.  
  51. return array(
  52.  
  53. "cslots" => $cslots,
  54.  
  55. "maxslots" => $maxslots,
  56.  
  57. "query" => $query
  58.  
  59. );
  60.  
  61. } else {
  62.  
  63. $errors = $sinfo['errors'];
  64.  
  65. }
  66.  
  67. } else {
  68.  
  69. $errors = $selected['errors'];
  70.  
  71. }
  72.  
  73. } else {
  74.  
  75. $errors = $connection['errors'];
  76.  
  77. }
  78.  
  79.  
  80.  
  81. file_put_contents('error_ts3info.log', $errors);
  82.  
  83.  
  84.  
  85. return array(
  86.  
  87. "cslots" => "--",
  88.  
  89. "maxslots" => "--",
  90.  
  91. "query" => "--"
  92.  
  93. );
  94.  
  95. }
  96.  
  97.  
  98.  
  99. function getTs3Info($ts3server, $ts3qport, $ts3port, $ts3user, $ts3pass) {
  100.  
  101. // Cache system
  102.  
  103. $driver = new Stash\Driver\FileSystem(array());
  104.  
  105. $pool = new Stash\Pool($driver);
  106.  
  107. $item = $pool->getItem('api/teamspeak/serverinfo/'.$ts3server);
  108.  
  109.  
  110.  
  111. // Using an age.
  112.  
  113. $data = $item->get();
  114.  
  115. if($item->isMiss())
  116.  
  117. {
  118.  
  119. $data = ts3info($ts3server, $ts3qport, $ts3port, $ts3user, $ts3pass);
  120.  
  121.  
  122.  
  123. $item->set($data);
  124.  
  125. $item->expiresAfter(60);
  126.  
  127. $pool->save($item);
  128.  
  129. }
  130.  
  131. return $data;
  132.  
  133. }
  134.  
  135.  
  136.  
  137. function getRustInfo($token, $servers) {
  138.  
  139. $rust = new Rust($token);
  140.  
  141. // Cache system
  142.  
  143. $driver = new Stash\Driver\FileSystem(array());
  144.  
  145. $pool = new Stash\Pool($driver);
  146.  
  147. // Get server infos
  148.  
  149. $serverInfo = array();
  150.  
  151. $i = 0;
  152.  
  153. // Rust info
  154.  
  155. $players = 0;
  156.  
  157. $maxplayers = 0;
  158.  
  159. foreach ($servers as $server=>$connect) {
  160.  
  161. $item = $pool->getItem('api/rust/serverinfo/'.$server);
  162.  
  163. // Using an age.
  164.  
  165. $data = $item->get();
  166.  
  167. if($item->isMiss())
  168.  
  169. {
  170.  
  171. $item->lock();
  172.  
  173.  
  174.  
  175. $newdata = $rust->getServerInfo($server);
  176.  
  177. // Respecting the rate limit ...
  178.  
  179. $i++;
  180.  
  181.  
  182.  
  183. if ($i%5==0) sleep(2);
  184.  
  185.  
  186.  
  187. if (!$newdata->error) {
  188.  
  189. $data = $newdata;
  190.  
  191. } else {
  192.  
  193. sleep(5);
  194.  
  195. }
  196.  
  197.  
  198.  
  199. $item->set($data);
  200.  
  201.  
  202.  
  203. // Cache expires after two minutes.
  204.  
  205. $item->expiresAfter(120);
  206.  
  207.  
  208.  
  209. $pool->save($item);
  210.  
  211. }
  212.  
  213. $data->connectUrl = $connect;
  214.  
  215. $serverInfo[$server] = $data;
  216.  
  217. $players += $data->getPlayers();
  218.  
  219. $maxplayers += $data->getMaxPlayers();
  220.  
  221. }
  222.  
  223.  
  224.  
  225. return array(
  226.  
  227. "players" => $players,
  228.  
  229. "maxplayers" => $maxplayers
  230.  
  231. );
  232.  
  233. }
  234.  
  235.  
  236.  
  237. function makeBanner($ts3info, $rustinfo) {
  238.  
  239. header('Content-type: image/png');
  240.  
  241. $datum = date("d.m.Y");
  242.  
  243. $uhrzeit = date("H:i");
  244.  
  245. //$text = "$uhrzeit Uhr | $datum | $cslots/$maxslots User(+$query)";
  246.  
  247. $image = imagecreatefrompng('GN_PHP_Banner.png');
  248.  
  249.  
  250.  
  251. $x = 40;
  252.  
  253.  
  254.  
  255. $cslots = $ts3info['cslots'];
  256.  
  257. $maxslots = $ts3info['maxslots'];
  258.  
  259. $teamspeak_text = "$cslots";
  260.  
  261. $text_color = imagecolorallocate($image, 255, 255, 255);
  262.  
  263. imagestring($image, 5, $x, 62, $teamspeak_text, $text_color);
  264.  
  265.  
  266.  
  267. $rplayers = $rustinfo['players'];
  268.  
  269. $rmaxplayers = $rustinfo['maxplayers'];
  270.  
  271. $rust_text = "$rplayers";
  272.  
  273. imagestring($image, 5, $x, 118, $rust_text, $text_color);
  274.  
  275.  
  276.  
  277. imagepng($image);
  278.  
  279. }
  280.  
  281.  
  282.  
  283. $ts3info = getTs3Info($ts3server, $ts3qport, $ts3port, $ts3user, $ts3pass);
  284.  
  285. $token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbiI6IjQzNGIxOTJjMTNlYzIwZWEiLCJpYXQiOjE0OTM0NzY1ODAsIm5iZiI6MTQ5MzQ3NjU4MCwiaXNzIjoiaHR0cHM6Ly93d3cuYmF0dGxlbWV0cmljcy5jb20iLCJzdWIiOiJ1cm46dXNlcjoxNDIwNyJ9.9-kpzL5hT0sBESupKjSVfDvmkBoPCHt2tUBCK9jlyIo';
  286.  
  287. $rustinfo = getRustInfo($token, $servers);
  288.  
  289. makeBanner($ts3info, $rustinfo);
  290.  
  291.  
  292.  
  293. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement