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
  1. <?php
  2. /**
  3. * Minecraft PHP Query Class
  4. * Copyright (C) 2012 Scott Reed (h02)
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19.  
  20. class MinecraftQuery
  21. {
  22. /**
  23. * Queries a Minecraft server
  24. *
  25. * @static
  26. * @param string $ip - IP address to the Minecraft server.
  27. * @param int $port - Port of the Minecraft server.
  28. * @param int $timeout - Time until giving up on connecting to the Minecraft server.
  29. * @return array|bool - An array on success, FALSE on failure.
  30. */
  31. public static function query($ip, $port = 25565, $timeout = 2)
  32. {
  33. $socket = @fsockopen($ip, $port, $errno, $errstr, $timeout);
  34.  
  35. if (!$socket) return false;
  36.  
  37. fwrite($socket, chr(254));
  38.  
  39. $response = "";
  40.  
  41. while(!feof($socket)) $response .= fgets($socket, 1024);
  42.  
  43. $result = array();
  44. $response = str_replace(chr(0),"",$response);
  45. $response = substr($response, 2);
  46. $query = preg_split("/[".chr(167)."]/", $response, -1, PREG_SPLIT_NO_EMPTY);
  47.  
  48. $result['hostname'] = trim($query[0]);
  49. $result['players'] = (int) $query[1];
  50. $result['maxplayers'] = (int) $query[2];
  51. return $result;
  52. }
  53. }
  54. ?>



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.

  1. case "minecraft":{
  2. $qq = new MinecraftQuery( );
  3. $pServers['minecraft'] = array('minecraft', $ip , $port );
  4.  
  5. //Wolne miejsce, gdzie muszę pobrać dane z protokołu
  6.  
  7. $im = imagecreatefrompng( MC_BACKGROUND );
  8.  
  9. if( $data[ 'minecraft' ][ 'hostname' ] ){
  10. $szHost = $data[ 'minecraft' ][ 'hostname' ];
  11. $iPlayers = $data[ 'minecraft' ][ 'players' ];
  12. $iPlayersMax = $data[ 'minecraft' ][ 'maxplayers' ];
  13. }
  14. else{
  15. $szHost = 'Serwer '.$server.' jest WYLACZONY';
  16. $iPlayers = "0";
  17. $iPlayersMax = "0";
  18. }
  19.  
  20. 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ł