Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Dodanie jednej opcji do skryptu
Karolus
post
Post #1





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 20.02.2012

Ostrzeżenie: (0%)
-----


  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

Ten post edytował Karolus 20.02.2012, 14:13:35
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 1)
wookieb
post
Post #2





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




Naucz się podstaw. Skoro nie umiesz zrobić takich podstaw to po co tutaj przychodzisz? Żebrać? Zamykam.


--------------------
Go to the top of the page
+Quote Post

Closed TopicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 07:37