Witam,
Miałem status graficzny chciałem do niego dodać parę gierek. Dodałem parę, ale z jedną nie mogę sobie poradzić. Słabo znam PHP jednak chciałbym to teraz skończyć.
Klasa która czyta nazwę serwera, liczbę graczy i maksymalną liczbę graczy
<?php
/**
* Minecraft PHP Query Class
* Copyright (C) 2012 Scott Reed (h02)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class MinecraftQuery
{
/**
* Queries a Minecraft server
*
* @static
* @param string $ip - IP address to the Minecraft server.
* @param int $port - Port of the Minecraft server.
* @param int $timeout - Time until giving up on connecting to the Minecraft server.
* @return array|bool - An array on success, FALSE on failure.
*/
public static function query
($ip, $port = 25565
, $timeout = 2
) {
$socket = @fsockopen($ip, $port, $errno, $errstr, $timeout);
if (!$socket) return false;
$response = "";
while(!feof($socket)) $response .= fgets($socket, 1024
);
$response = substr($response, 2
); $query = preg_split("/[".chr
(167)."]/", $response, -1
, PREG_SPLIT_NO_EMPTY
);
$result['hostname'] = trim($query[0
]); $result['players'] = (int) $query[1];
$result['maxplayers'] = (int) $query[2];
return $result;
}
}
?>
Pod różne wykorzystanie gier wykorzystałem składnię switch, którą będę mógł sobie wybierać odpowiednie gry, ale dobra przejdźmy do sedna.
case "minecraft":{
$qq = new MinecraftQuery( );
$pServers['minecraft'] = array('minecraft', $ip , $port );
//Wolne miejsce, gdzie muszę pobrać dane z protokołu
$im = imagecreatefrompng( MC_BACKGROUND );
if( $data[ 'minecraft' ][ 'hostname' ] ){
$szHost = $data[ 'minecraft' ][ 'hostname' ];
$iPlayers = $data[ 'minecraft' ][ 'players' ];
$iPlayersMax = $data[ 'minecraft' ][ 'maxplayers' ];
}
else{
$szHost = 'Serwer '.$server.' jest WYLACZONY';
$iPlayers = "0";
$iPlayersMax = "0";
}
break;
Zaznaczyłem gdzie jest wolne miejsce gdzie muszę wpisać dane z protokołu, jak ich nie wpiszę to oczywiście wywala else Serwer xx.xxx.xx jest wyłączony. W innych statusach było to coś takiego, ale to chyba jest zależne od protokołu.
$qq -> addServers( $pServers );
$data = $qq -> requestData();
Nie za bardzo to rozumiem, tak więc prosiłbym o pomoc, bo główkuję już parę godzin i liczę na pomoc.
Pozdrawiam
Duo
odświeżam, bardzo zależy mi na tym, żeby skrypt działał