Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once __DIR__.'/../../wp-content/themes/galaxynetwork/lib/vendor/autoload.php';
- require_once __DIR__.'/../../wp-content/themes/galaxynetwork/template-parts/rust/Rust.class.php';
- require_once __DIR__.'/../../wp-content/themes/galaxynetwork/template-parts/rust/servers.php';
- require_once(__DIR__."/ts3admin.class.php");
- require_once(__DIR__."/connect.php");
- function ts3info($ts3server, $ts3qport, $ts3port, $ts3user = null, $ts3pass = null) {
- $ts3 = new ts3admin($ts3server, $ts3qport);
- $connection = $ts3->connect();
- if ($connection['success']) {
- $selected = $ts3->selectServer($ts3port, 'port', true);
- if ($selected['success']) {
- if ($ts3user != null && $ts3pass != null) {
- $login = $ts3->login($ts3user, $ts3pass);
- }
- $sinfo = $ts3->serverInfo();
- if ($sinfo['success']) {
- $sinfo = $sinfo["data"];
- $cslots = intval($sinfo["virtualserver_clientsonline"])-intval($sinfo["virtualserver_queryclientsonline"]);
- $maxslots = intval($sinfo["virtualserver_maxclients"]);
- $query = intval($sinfo["virtualserver_queryclientsonline"])-1;
- return array(
- "cslots" => $cslots,
- "maxslots" => $maxslots,
- "query" => $query
- );
- } else {
- $errors = $sinfo['errors'];
- }
- } else {
- $errors = $selected['errors'];
- }
- } else {
- $errors = $connection['errors'];
- }
- file_put_contents('error_ts3info.log', $errors);
- return array(
- "cslots" => "--",
- "maxslots" => "--",
- "query" => "--"
- );
- }
- function getTs3Info($ts3server, $ts3qport, $ts3port, $ts3user, $ts3pass) {
- // Cache system
- $driver = new Stash\Driver\FileSystem(array());
- $pool = new Stash\Pool($driver);
- $item = $pool->getItem('api/teamspeak/serverinfo/'.$ts3server);
- // Using an age.
- $data = $item->get();
- if($item->isMiss())
- {
- $data = ts3info($ts3server, $ts3qport, $ts3port, $ts3user, $ts3pass);
- $item->set($data);
- $item->expiresAfter(60);
- $pool->save($item);
- }
- return $data;
- }
- function getRustInfo($token, $servers) {
- $rust = new Rust($token);
- // Cache system
- $driver = new Stash\Driver\FileSystem(array());
- $pool = new Stash\Pool($driver);
- // Get server infos
- $serverInfo = array();
- $i = 0;
- // Rust info
- $players = 0;
- $maxplayers = 0;
- foreach ($servers as $server=>$connect) {
- $item = $pool->getItem('api/rust/serverinfo/'.$server);
- // Using an age.
- $data = $item->get();
- if($item->isMiss())
- {
- $item->lock();
- $newdata = $rust->getServerInfo($server);
- // Respecting the rate limit ...
- $i++;
- if ($i%5==0) sleep(2);
- if (!$newdata->error) {
- $data = $newdata;
- } else {
- sleep(5);
- }
- $item->set($data);
- // Cache expires after two minutes.
- $item->expiresAfter(120);
- $pool->save($item);
- }
- $data->connectUrl = $connect;
- $serverInfo[$server] = $data;
- $players += $data->getPlayers();
- $maxplayers += $data->getMaxPlayers();
- }
- return array(
- "players" => $players,
- "maxplayers" => $maxplayers
- );
- }
- function makeBanner($ts3info, $rustinfo) {
- header('Content-type: image/png');
- $datum = date("d.m.Y");
- $uhrzeit = date("H:i");
- //$text = "$uhrzeit Uhr | $datum | $cslots/$maxslots User(+$query)";
- $image = imagecreatefrompng('GN_PHP_Banner.png');
- $x = 40;
- $cslots = $ts3info['cslots'];
- $maxslots = $ts3info['maxslots'];
- $teamspeak_text = "$cslots";
- $text_color = imagecolorallocate($image, 255, 255, 255);
- imagestring($image, 5, $x, 62, $teamspeak_text, $text_color);
- $rplayers = $rustinfo['players'];
- $rmaxplayers = $rustinfo['maxplayers'];
- $rust_text = "$rplayers";
- imagestring($image, 5, $x, 118, $rust_text, $text_color);
- imagepng($image);
- }
- $ts3info = getTs3Info($ts3server, $ts3qport, $ts3port, $ts3user, $ts3pass);
- $token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbiI6IjQzNGIxOTJjMTNlYzIwZWEiLCJpYXQiOjE0OTM0NzY1ODAsIm5iZiI6MTQ5MzQ3NjU4MCwiaXNzIjoiaHR0cHM6Ly93d3cuYmF0dGxlbWV0cmljcy5jb20iLCJzdWIiOiJ1cm46dXNlcjoxNDIwNyJ9.9-kpzL5hT0sBESupKjSVfDvmkBoPCHt2tUBCK9jlyIo';
- $rustinfo = getRustInfo($token, $servers);
- makeBanner($ts3info, $rustinfo);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement