| Autor | Zpráva | ||
|---|---|---|---|
| Thewest123 Profil |
Zdravím Všechny,
mám udělaný script na získání statusu serveru podobně jako tady: PHP Online Status ( https://github.com/FunnyItsElmo/PHP-Minecraft-Server-Status-Query ) ( Vypadá nějak takto: http://test.vycraftito.eu/status ) index.php <?php
$server = 's1.vycraftito.eu'; // IP nebo adresa
$port = 25592; // port serveru
$verze = '1.7.*';
include_once 'MinecraftServerStatus/status.class.php';
$status = new MinecraftServerStatus();
$response = $status->getStatus($server, $verze, $port);
//$response = $status->getStatus('pvp24.com');
if(!$response) {
header('Content-Type: image/png');
$image_width = 600; // px
$image_height = 150; // px
$im = imagecreatefrompng("vycraftito-status-offline.png");
// Nastav barvy
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
$yellow = imagecolorallocate($im, 238, 254, 101);
$red = imagecolorallocate($im, 255,0,0);
$blue = imagecolorallocate($im, 0,0,255);
$green = imagecolorallocate($im, 0,255,51);
$green2 = imagecolorallocate($im, 0,153,0);
$font_file = 'arialbd.ttf'; // umĂstÄ›nĂ
$font = 'obx.ttf';
//Vykresleni Obrysu Textu
//Online
imagefttext($im, 25, 0, 220, 127, $black, $font, 'Offline');
imagefttext($im, 25, 0, 220, 123, $black, $font, 'Offline');
imagefttext($im, 25, 0, 222, 125, $black, $font, 'Offline');
imagefttext($im, 25, 0, 218, 125, $black, $font, 'Offline');
//Vykresleni Textu
imagefttext($im, 25, 0, 220, 125, $red, $font, 'Offline');
imagepng($im);
} else {
header('Content-Type: image/png');
$image_width = 600; // px
$image_height = 150; // px
$im = imagecreatefrompng("vycraftito-status.png");
// Nastav barvy
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
$yellow = imagecolorallocate($im, 238, 254, 101);
$red = imagecolorallocate($im, 204,0,0);
$blue = imagecolorallocate($im, 0,0,255);
$green = imagecolorallocate($im, 0,255,51);
$green2 = imagecolorallocate($im, 0,153,0);
$font_file = 'arialbd.ttf'; // umisteni fontu
$font = 'obx.ttf';
//Vykresleni Obrysu Textu
//Online
imagefttext($im, 22, 0, 245, 117, $black, $font, 'Online');
imagefttext($im, 22, 0, 245, 113, $black, $font, 'Online');
imagefttext($im, 22, 0, 247, 115, $black, $font, 'Online');
imagefttext($im, 22, 0, 243, 115, $black, $font, 'Online');
//Players
imagefttext($im, 25, 0, 130, 132, $black, $font_file, ''.$response['players']);
imagefttext($im, 25, 0, 130, 128, $black, $font_file, ''.$response['players']);
imagefttext($im, 25, 0, 132, 130, $black, $font_file, ''.$response['players']);
imagefttext($im, 25, 0, 128, 130, $black, $font_file, ''.$response['players']);
//MaxPlayers
imagefttext($im, 25, 0, 455, 132, $black, $font_file, ''.$response['maxplayers']);
imagefttext($im, 25, 0, 455, 128, $black, $font_file, ''.$response['maxplayers']);
imagefttext($im, 25, 0, 453, 130, $black, $font_file, ''.$response['maxplayers']);
imagefttext($im, 25, 0, 457, 130, $black, $font_file, ''.$response['maxplayers']);
//Verze
imagefttext($im, 11, 0, 252, 135, $black, $font_file, ''.$response['version']);
imagefttext($im, 11, 0, 252, 133, $black, $font_file, ''.$response['version']);
imagefttext($im, 11, 0, 253, 134, $black, $font_file, ''.$response['version']);
imagefttext($im, 11, 0, 251, 134, $black, $font_file, ''.$response['version']);
//Vykresleni Textu
imagefttext($im, 22, 0, 245, 115, $green, $font, 'Online');
imagefttext($im, 25, 0, 130, 130, $yellow, $font_file, ''.$response['players']);
imagefttext($im, 25, 0, 455, 130, $yellow, $font_file, ''.$response['maxplayers']);
imagefttext($im, 11, 0, 252, 134, $white, $font_file, ''.$response['version']);
imagepng($im);
}
// vycisti cache
imagedestroy($im);
?>Problém je, že to funguje pouze na port začínající na 25 (25565, 25789 atd..) Zkoušel jsem to trochu upravit s použitím jiné classy ( https://github.com/xPaw/PHP-Minecraft-Query ) Index.php tudíž vypadá nějak takto <?php
$server = 's1.vycraftito.eu'; // IP nebo adresa
$port = 25592; // port serveru
//$verze = '1.7.*';
require 'MinecraftQuery.class.php';
$Query = new MinecraftQuery( );
$Query = new MinecraftQuery();
$Query->Connect($server, $port);
$Info = $Query->GetInfo();
header('Content-Type: image/png');
$image_width = 600; // px
$image_height = 150; // px
$im = imagecreatefrompng("vycraftito-status.png");
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
$yellow = imagecolorallocate($im, 238, 254, 101);
$red = imagecolorallocate($im, 204,0,0);
$blue = imagecolorallocate($im, 0,0,255);
$green = imagecolorallocate($im, 0,255,51);
$green2 = imagecolorallocate($im, 0,153,0);
$font_file = 'arialbd.ttf'; // umisteni fontu
$font = 'obx.ttf';
imagefttext($im, 11, 0, 252, 134, $white, $font_file, $Info['Players']);
imagepng($im);
//echo $Info['HostName']
// vycisti cache
imagedestroy($im);
?>Pokud někdo ví, kde mám chybu, budu rád za odpověď, děkuji :) |
||
| Alphard Profil |
#2 · Zasláno: 17. 11. 2014, 11:53:52
Obvyklá rada, neposílat hlavičku obrázku a přečíst si ta chybová hlášení.
|
||
| juriad Profil |
#3 · Zasláno: 17. 11. 2014, 11:55:16
Ten soubor png obsahuje na začátku dva řádky HTML:
<br /> <b>Warning</b>: imagefttext(): Could not find/open font in <b>/data/web/virtuals/62354/virtual/www/subdom/test/q/index.php</b> on line <b>29</b><br /> |
||
| Thewest123 Profil |
#4 · Zasláno: 17. 11. 2014, 12:11:17
Já jsem věděl, že to bude taková prkotina, už to fachá :D
Zapoměl jsem tam dát font. Ještě malý dotaz: Kde se mi zobrazí ty chové hlášení? S php začínám :D |
||
| juriad Profil |
#5 · Zasláno: 17. 11. 2014, 12:18:18
Thewest123:
Já jsem si wgetem stáhnul tu adresu. Uložil mi to do souboru index.html a prostě jsem se podíval dovnitř. Jinak, jak radí Alphard, stačí odstranit header('Content: image/png') - pak se obrázek zobrazí jako text a ten warning se tam ukáže.
|
||
| Thewest123 Profil |
#6 · Zasláno: 17. 11. 2014, 13:29:33
Super, vše funguje ok. Když je server zapnutý, zobrazí se obrázek vycraftito-status.png
Když je ale server vypnutý, zobrazí se: Fatal error: Uncaught exception 'MinecraftQueryException' with message 'Failed to receive challenge.' in /data/web/virtuals/62354/virtual/www/subdom/test/q/MinecraftQuery.class.php:51 Stack trace: #0 /data/web/virtuals/62354/virtual/www/subdom/test/q/index.php(10): MinecraftQuery->Connect('s1.vycraftito.e...', 25592) #1 {main} thrown in /data/web/virtuals/62354/virtual/www/subdom/test/q/MinecraftQuery.class.php on line 51Nevíte, jak mám udělat, aby se při vypnutém serveru zobrazil vycraftito-status-offline.png? Díky |
||
| juriad Profil |
Thewest123:
Musíš se zkus připojit a když se to nezdaří použiješ jiný obrázek: try {
... connect ...
readfile('vycraftito-status.png ');
} catch (Exception $e) {
readfile('vycraftito-status-offline.png ');
} |
||
| yFang Profil |
#8 · Zasláno: 17. 11. 2014, 13:34:54
Thewest123:
Odchytit vyjímku MinecraftQueryException. Pokud nastane, tak zobrazit ten druhý obrázek. O vyjímkách si můžeš přečíst na stránkách php http://php.net/manual/en/language.exceptions.php |
||
| Thewest123 Profil |
#9 · Zasláno: 17. 11. 2014, 13:48:28
Funguje TO!
Díky moc vám všem! A hlavně tobě juriad :) Prosím o Lock ;) |
||
| juriad Profil |
#10 · Zasláno: 17. 11. 2014, 13:50:58
Thewest123:
Tady nezamykáme. Vlákno postupně zapadne do historie. A třeba se někdy bude někde chtít zeptat na nějaký detail... |
||
|
Časová prodleva: 11 let
|
|||
0