Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Dodanie jednej opcji do skryptu
Forum PHP.pl > Forum > PHP
Karolus
  1. <?php
  2. /******************************************************************\
  3.   |* Copyright (c) by starlex.de, Alexander Becker
  4.   |*
  5.   |* Visit:
  6.   |*
  7.   |* License:
  8.   |*
  9.   \******************************************************************/
  10.  
  11.  
  12. $serverstatus = mc_status("176.31.240.28:25567"); // <- your serveraddress here
  13. echo ("motd: ".$serverstatus["motd"]);
  14. echo ("\n<br/>\n");
  15. echo ("players: ".$serverstatus["cur_players"]."/".$serverstatus["max_players"]);
  16.  
  17. function mc_status( $server ) {
  18. if($socket = stream_socket_client('tcp://'.$server , $errno, $errstr, 1)) // connect to the server
  19. {
  20. fwrite($socket, "\xfe"); // writes the query
  21. $tmp = fread($socket, 2048); // reads the serverinfo
  22. $tmp = str_replace("\x00","",$tmp); // removes all 0x00
  23. $tmp = substr ($tmp,2); // removes the first 2 bytes
  24.  
  25. $info = explode("§",$tmp); // splits the sting into a array
  26. unset($tmp);
  27.  
  28. if(count($info) == 3) // check array (if modt contains invalid chars(§))
  29. {
  30.  
  31. return( // returns a new Array (END)
  32. "motd" => $info[0],
  33. "cur_players" => $info[1],
  34. "max_players" => $info[2]
  35. )
  36. );
  37.  
  38. } else if(count($info) > 3){ // DEAL ERRORS - INVALID CHARS : !!! not added in the minecraft client !!!
  39.  
  40. $tmp = "";
  41. for ($i = 0; $i < count($info) - 2; $i++) {
  42. $tmp .= $info[$i];
  43. if(!($i == count($info) - 2 - 1))
  44. {
  45. $tmp .= "§";
  46. }
  47. }
  48.  
  49. return( // returns a new Array (END)
  50. "motd" => $tmp,
  51. "cur_players" => $info[count($info) - 2],
  52. "max_players" => $info[count($info) - 1]
  53. )
  54. );
  55.  
  56. } else {
  57. return false; // return false (if syntax is wrong)
  58. }
  59.  
  60. } else {
  61. return false; // return false (if connection failed in first step)
  62. }
  63. }
  64. ?>


Witam, powyższy skrypt pokazuję na stronie ile graczy jest online w danym momencie na serwerze Minecraft.
Chciałbym żeby w momencie wyłączenia serwera pokazywał:
-"/".$serverstatus["max_players"]);

np. -/40

Ewentualnie mogę na sztywno zamienić wartość max_players na liczbę slotów.
Ponieważ w tym momencie kiedy serwer jest wyłączony pokazuje on błędy.

Pozdrawiam
wookieb
Naucz się podstaw. Skoro nie umiesz zrobić takich podstaw to po co tutaj przychodzisz? Żebrać? Zamykam.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.