<?php

error_reporting(E_ALL);
include "inc/ServerQueries.php";
include "inc/SourceServerQueries.php";

$url = "banner.png"; // путь, название картинки

if (isset($_GET["serv"]))
{
    $sq = new SourceServerQueries();
    $server = $_GET["serv"];
    $address = explode(':', $server);
    $sq->connect($address[0], $address[1]);
    $info = $sq->getInfo();
    //print_r($info);
    $players = $sq->getPlayers();
    //print_r($players);
    $rules = $sq->getRules();
    //print_r($rules);
    $sq->disconnect();
    //flush();

    header("Content-type: image/png");
    $img = imagecreatefrompng($url);
    $white = imagecolorallocate($img, 255, 255, 255);
    $black = imagecolorallocate($img, 0, 0, 0);
    $green = imagecolorallocate($img, 0, 255, 0);
    $brown = imagecolorallocate($img, 255, 85, 0);
    $red = imagecolorallocate($img, 255, 0, 0);

    if ($info['serverName'])
    {

        $players = $info['playerNumber'] . " / " . $info['maxPlayers'];
        $status = "Включен";
        $color = $green;
    } else
    {
        $server_full = " ";
        $players = "Нет игроков";
        $status = "Выключен";
        $color = $red;
    }
    //imagettftext (resource image, int size, int angle, int x, int y, int color, string fontfile, string text)
    imagettftext($img, 10, 0, 120, 18, $brown, "fonts/arial.ttf", iconv('WINDOWS-1251',
        'UTF-8', "Сервер:"));
    imagettftext($img, 10, 0, 120, 34, $white, "fonts/arialbd.ttf", isset($info['serverName']) ?
        $info['serverName'] : '');

    imagettftext($img, 10, 0, 320, 18, $brown, "fonts/arial.ttf", iconv('WINDOWS-1251',
        'UTF-8', "Время на карте:"));
    imagettftext($img, 9, 0, 350, 34, $white, "fonts/arialbd.ttf", isset($rules['amx_timeleft']) ?
        $rules['amx_timeleft'] : '');

    imagettftext($img, 10, 0, 480, 18, $brown, "fonts/arial.ttf", iconv('WINDOWS-1251',
        'UTF-8', "Статус:"));
    imagettftext($img, 9, 0, 490, 34, $color, "fonts/arialbd.ttf", iconv('WINDOWS-1251',
        'UTF-8', $status));

    imagettftext($img, 10, 0, 120, 57, $brown, "fonts/arial.ttf", iconv('WINDOWS-1251',
        'UTF-8', "Адрес:"));
    imagettftext($img, 9, 0, 120, 72, $white, "fonts/arialbd.ttf", $server);

    imagettftext($img, 10, 0, 265, 57, $brown, "fonts/arial.ttf", iconv('WINDOWS-1251',
        'UTF-8', "Карта:"));
    imagettftext($img, 9, 0, 265, 72, $white, "fonts/arialbd.ttf", isset($info['mapName']) ?
        $info['mapName'] : '');

    imagettftext($img, 10, 0, 370, 57, $brown, "fonts/arial.ttf", iconv('WINDOWS-1251',
        'UTF-8', "След.карта:"));
    imagettftext($img, 9, 0, 370, 72, $white, "fonts/arialbd.ttf", isset($rules['amx_nextmap']) ?
        $rules['amx_nextmap'] : '');

    imagettftext($img, 10, 0, 490, 57, $brown, "fonts/arial.ttf", iconv('WINDOWS-1251',
        'UTF-8', "Игроки:"));
    imagettftext($img, 9, 0, 490, 72, $white, "fonts/arialbd.ttf", iconv('WINDOWS-1251',
        'UTF-8', $players));

    imagettftext($img, 8, 0, 415, 88, $green, "fonts/arialbd.ttf", iconv('WINDOWS-1251',
        'UTF-8', $server_full));


    imagePNG($img);
    imagedestroy($img);
}

?> 