Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Problem ze skryptem php
Forum PHP.pl > Forum > PHP
2late4u
Witam, mam problem ze skryptem który w założeniach miał wyświetlać obecny status serwera gry counter strike.
Skrypt jednak jakby nie łączył się z serwerem ponieważ pokazuje informację która ma być zwracana w przypadku offline'a.
co widać w praktyce: http://www.autoradprofit.bydgoszcz.pl/stat...72.37.178:27015
ja dopiero co raczkuje w php więc proszę o pomoc.
załączam całość w rar'ku
z góry dzięki.

http://www.speedyshare.com/files/24953063/status.rar
Fifi209
Wrzuć skrypt na forum - to jest w Twoim interesie.
Wątpię, że ktoś będzie pobierał nieznane pliki.
2late4u
Proszę bardzo:
  1. <?php
  2. require_once('status/class.hlsocket.php');
  3. define('TEMPESTA', 'status/fonts/tempesta.ttf');
  4. define('TAHOMA', 'status/fonts/tahoma.ttf');
  5. define('VERDANA', 'status/fonts/verdana.ttf');
  6. define('TAHOMA_BOLD', 'status/fonts/tahoma_bold.ttf');
  7. $server = $_GET['server'];
  8. if (isset($server) && !empty($server)) {
  9. list($ip, $port) = explode(":", $server);
  10. $s1_status = new HLSocket($ip, $port);
  11. $s1_info = $s1_status->details();
  12. if($s1_info['hostname']=="")
  13. {
  14. $hostname = 'Serwer '.$server.' jest OFFLINE';
  15. $players = "x";
  16. $playersmax = "x";
  17. $map = "OFFLINE";
  18. }
  19. else
  20. {
  21. $hostname = $s1_info['hostname'];
  22. $players = $s1_info['players'];
  23. $playersmax = $s1_info['max'];
  24. $map = $s1_info['map'];
  25. }
  26. $im = imagecreatefrompng("status/background.png");
  27. $white = imagecolorallocate($im, 255, 255, 255);
  28. $info = $server ." ". $players ." / ". $playersmax ." ". $map;
  29. imagettftext($im, 7, 0, 30, 10, $white, VERDANA, $hostname);
  30. imagettftext($im, 7, 0, 30, 21, $white, VERDANA, $info);
  31.  
  32. } else {
  33. $im = imagecreatefrompng("status/background.png");
  34. $white = imagecolorallocate($im, 255, 255, 255);
  35. $info = "123.456:27015 31 / 32 de_inferno";
  36. imagettftext($im, 7, 0, 30, 10, $white, VERDANA, "test @ freefrags.pl");
  37. imagettftext($im, 7, 0, 30, 21, $white, VERDANA, $info);
  38. }
  39.  
  40. header('Content-type: image/png');
  41. imagepng($im);
  42. imagedestroy($im);
  43. ?>
lDoran
daj jeszcze klasę HLSocket
2late4u
  1. <?php
  2. define('A2S_INFO', "\xFF\xFF\xFF\xFF\x54\x53\x6F\x75\x72\x63\x65\x20\x45\x6E\x67\x69\x6E\x65\x20\x51\x75\x65\x72\x79\x00");
  3. define('REPLY_INFO_HL1', 'm');
  4. define('REPLY_INFO_HL2', 'I');
  5. define('BYTE', 1);
  6. define('BYTE_NUM', BYTE + 1);
  7. define('SHORT', BYTE_NUM + 1);
  8. define('LONG', SHORT + 1);
  9. define('FLOAT', LONG + 1);
  10. define('STRING', FLOAT + 1);
  11. class HLSocket
  12. {
  13. var $_socket;
  14. var $_split_info_hl2 = array('type' => BYTE, 'bersion' => BYTE_NUM, 'hostname' => STRING, 'map' => STRING, 'gamedir' => STRING, 'gamedesc' => STRING, 'appid' => SHORT, 'unknown' => BYTE_NUM, 'players' => BYTE_NUM, 'max' => BYTE_NUM, 'bots' => BYTE_NUM, 'dedicated' => BYTE, 'os' => BYTE, 'passworded' => BYTE_NUM, 'secure' => BYTE_NUM, 'gameversion' => STRING);
  15. var $_split_info_hl1 = array('type' => BYTE, 'ip' => STRING, 'hostname' => STRING, 'map' => STRING, 'gamedir' => STRING, 'gamedesc' => STRING, 'players' => BYTE_NUM, 'max' => BYTE_NUM, 'version' => BYTE_NUM, 'dedicated' => BYTE, 'os' => BYTE, 'passworded' => BYTE_NUM, 'secure' => BYTE_NUM, 'gameversion' => STRING);
  16. function HLSocket($host, $port)
  17. {
  18. $this->connect($host, $port);
  19. $this->port = $port;
  20. $this->host = $host;
  21. }
  22.  
  23. function connect($host, $port)
  24. {
  25. $this->_socket = @fsockopen('udp://'.$host, $port);
  26. if (!$this->_socket)
  27. echo 'Error met connecten';
  28. stream_set_timeout($this->_socket, 1);
  29. }
  30.  
  31. function close()
  32. {
  33. fclose($this->_socket);
  34. }
  35.  
  36.  
  37. function details()
  38. {
  39. $this->write(A2S_INFO);
  40. $data = $this->read();
  41. $res = array();
  42. switch(substr($data, 0, 1))
  43. {
  44. case REPLY_INFO_HL1:
  45. $res = $this->split($this->_split_info_hl1, $data);
  46. break;
  47. case REPLY_INFO_HL2:
  48. $res = $this->split($this->_split_info_hl2, $data);
  49. break;
  50. }
  51. return $res;
  52. }
  53.  
  54.  
  55. function write($msg)
  56. {
  57. fwrite($this->_socket, $msg);
  58. }
  59.  
  60.  
  61. function read()
  62. {
  63. $data = fread($this->_socket, 1);
  64. $status = socket_get_status($this->_socket);
  65. if (isset($status['unread_bytes']) && $status['unread_bytes'] > 0)
  66. $data .= fread($this->_socket, $status['unread_bytes']);
  67. return substr($data, 4);
  68. }
  69.  
  70. function splititem($type, &$data) {
  71. $add = '';
  72. switch ($type)
  73. {
  74. case BYTE:
  75. $add = substr($data, 0, 1);
  76. $data = substr($data, 1);
  77. break;
  78. case BYTE_NUM:
  79. $add = ord(substr($data, 0, 1));
  80. $data = substr($data, 1);
  81. break;
  82. case SHORT:
  83. $add = ord(substr($data, 0, 1));
  84. $data = substr($data, 1);
  85. break;
  86. case LONG:
  87. $add = ord(substr($data, 0, 1));
  88. $data = substr($data, 1);
  89. break;
  90. case STRING:
  91. do
  92. {
  93. $char = substr($data, 0, 1);
  94. if ($char != "\x00")
  95. $add .= $char;
  96. $data = substr($data, 1);
  97. }
  98. while ($char != "\x00");
  99. break;
  100. }
  101. return $add;
  102. }
  103. function split($array, $data)
  104. {
  105. $res = array();
  106. foreach ($array as $k=>$v)
  107. $res[$k] = $this->splititem($v, $data);
  108. return $res;
  109. }
  110. }
  111. ?>
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.